java.io.IOException: specified 'source' attribute "A" does not match any node ID
at edu.uci.ics.jung.io.GraphMLReader.parse(GraphMLReader.java:246)
at edu.uci.ics.jung.io.GraphMLReader.load(GraphMLReader.java:192)
at hyperGraph.loadGraph(hyperGraph.java:189)
at hyperGraph.main(hyperGraph.java:233)
here is my loading graph code
class VertexM {
String name = "";
public VertexM() {
}
public VertexM(String name) {
this.name = name;
}
public String toString() {
return name;
}
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj == null) {
return false;
}
VertexM other = (VertexM) obj;
boolean a = this.getName().equals(other.getName());
return a;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public int getCount() {
return 1;
}
public int hashCode() {
return name.hashCode();
}
}
class EdgeM {
float count;
String id = "";
public EdgeM() {
this.count = 0;
}
public EdgeM(String d, String v1, String v2) {
this.id = v1 + v2;
this.count = Integer.parseInt(d);
}
public String toString() { // Always good for debugging
return id;
}
public void addCount() {
count++;
}
public void setId(String id) {
this.id = id;
}
public float getCount() {
return count;
}
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
)
if (obj == null) {
return false;
}
EdgeM other = (EdgeM) obj;
boolean a = this.toString().equals(other.toString());
return a;
}
@Override
public int hashCode() {
int result = Math.round(count) * 37 + id.hashCode();
return result;
}
}
public static UndirectedSparseGraph<VertexM, EdgeM> loadGraph(Reader reader) {
class EdgeMFactory implements Factory<EdgeM> {
@Override
public EdgeM create() {
return new EdgeM();
}
}
class VertexMFactory implements Factory<VertexM> {
public VertexM create() {
return new VertexM();
}
}
GraphMLReader<UndirectedSparseGraph<VertexM, EdgeM>, VertexM, EdgeM> graphReader =
null;
try {
graphReader = new GraphMLReader<UndirectedSparseGraph<VertexM, EdgeM>, VertexM,
EdgeM>(
new VertexMFactory(), new EdgeMFactory());
} catch (ParserConfigurationException e1) {
e1.printStackTrace();
} catch (SAXException e1) {
e1.printStackTrace();
}
UndirectedSparseGraph<VertexM, EdgeM> fixGraph = new
UndirectedSparseGraph<VertexM, EdgeM>();
try {
graphReader.load(reader, fixGraph);
Map<String, GraphMLMetadata<VertexM>> nodeMetaData = graphReader
.getVertexMetadata();
for (VertexM node : fixGraph.getVertices()) {
String nodeName = ((String)
(nodeMetaData.get("NodeName").transformer.transform(node)));
System.out.println("NODE" + nodeName);
node.setName(nodeName);
}
} catch (IOException e) {
e.printStackTrace();
}
return fixGraph;
}
/**
* @param args
* @throws SAXException
* @throws ParserConfigurationException
*/
public static void main(String[] args) {
try { FileReader in = new FileReader(
"C:\\Program Files\\Eclipse for FYP\\output\\test.txt");
Hypergraph<VertexM, EdgeM> hg = loadGraph(in);
System.out.println(hg.getVertices()); } catch
(ArrayIndexOutOfBoundsException e) {
System.out.println("Usage: java ReadFile filename\n");
} catch (IOException e) { e.printStackTrace(); }
}
my save file is
<?xml version="1.0" encoding="UTF-8"?> <graphml xmlns="http://graphml.graphdrawing.org/xmlns/graphml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://graphml.graphdrawing.org/xmlns/graphml"> <key id="NodeName" for="node"> <desc>File Name</desc> <default></default> </key> <key id="EdgeName" for="edge"> <desc>Edge Visit Name</desc> <default></default> </key> <key id="EdgeCount" for="edge"> <desc>Edge Visit Count</desc> <default></default> </key> <graph edgedefault="undirected"> <node id="A"> <data key="NodeName">A</data> </node> <node id="B"> <data key="NodeName">B</data> </node> <node id="C"> <data key="NodeName">C</data> </node> <edge source="A" target="C"> <data key="EdgeName">AC</data> <data key="EdgeCount">3.0</data> </edge> <edge source="A" target="B"> <data key="EdgeName">AB</data> <data key="EdgeCount">2.0</data> </edge> </graph> </graphml>
is there any problem for my code?
Edited by Dogstopper:

New Topic/Question
Reply




MultiQuote








|