Tuesday, July 28, 2009

Java programming compile error?

what do i have to do to get this to compile?








import GraphPackage.*;





public class lab3026


{


public static void main(String [] args)


{








BasicGraphInterface%26lt;String%26gt; airMap = new UndirectedGraph%26lt;String%26gt;();





airMap.addVertex("Boston");


airMap.addVertex("Provincetown");


airMap.addVertex("Nantucket");


airMap.addEdge("Boston", "Provincetown");


airMap.addEdge("Boston", "Nantucket");





airMap.getNumberOfVertices();


airMap.getNumberOfEdges();





}


}








C:\Documents and Settings\HP_Administrator\Desktop\New Folder\lab3026.java:9: '(' or '[' expected


BasicGraphInterface%26lt;String%26gt; airMap = new UndirectedGraph%26lt;String%26gt;();


^


1 error





Tool completed with exit code 1

Java programming compile error?
first, import GraphPackage might be wrong .. package names in java are supposed to be lowercase, so first try changing to import graphpackage.*;





then if still a problem ensure you are running Java 5 or 6 so that the generic type %26lt;String%26gt; is understood by the compiler.





then if still failing, are you sure the BasicGraphInterface should have the generic type definition after it? Try removing those to test so you have BasicGraphInterface airMap = new UndirectedGraph();





you also have a typo on airMap.addVertex("Provincetown... as you do not end with ");





i cant see much else wrong here so ultimately if still an issue, the graphpackage class itself might have a fault.


No comments:

Post a Comment