Results 1 to 8 of 8
- 06-19-2011, 12:14 PM #1
Member
- Join Date
- Jun 2011
- Posts
- 4
- Rep Power
- 0
Having problem with Ajacency Graph
hi, I have problem with this code. I want to return an Iterator<Edge<E>> in incidentEdges(xx) method but it gives error. Some type missmatch,, why
Adv.Java Code:public class AdjacencyListGraph<V,E> implements Graph<V,E>{ private List<Vertex<V>> vertices; //the vertices of the graph private List<Edge<E>> edges; //the edges of the graph .... @Override public Iterator<Edge<E>> incidentEdges(Vertex<V> v) { ALVertex vertex = check(v); Iterator<Edge<E>> iter = vertex.getEdges().iterator(); return iter; } .... } private class ALVertex implements Vertex<V>{ private V element; private ArrayList<ALEdge> edges = new ArrayList<ALEdge>(); .... public ArrayList<ALEdge> getEdges(){ return edges; } ..... } private class ALEdge implements Edge<E>{ private E element; .... @Override public E element() { return element; } .... }
Thanks
Last edited by kursist; 06-19-2011 at 02:04 PM.
- 06-19-2011, 01:47 PM #2
When you get errors, please copy and paste here the full text of the error message. That will speed things up.but it gives error. Some type missmatch
Also please surround your code with code tags. See: http://www.java-forums.org/misc.php?do=bbcode#code
- 06-19-2011, 02:04 PM #3
Member
- Join Date
- Jun 2011
- Posts
- 4
- Rep Power
- 0
- 06-19-2011, 02:15 PM #4
Is that true? Can you convert the one type to the other? The compiler doesn't see how to do it.cannot convert from Iterator<AdjacencyListGraph<V,E>.ALEdge> to Iterator<Edge<E>>
Your posting of the error didn't show the source line that caused the error.
- 06-19-2011, 02:22 PM #5
Member
- Join Date
- Jun 2011
- Posts
- 4
- Rep Power
- 0
Last edited by kursist; 06-19-2011 at 02:30 PM.
- 06-19-2011, 03:52 PM #6
What don't you understand about the error message?
The compiler finds one type on the left of the = and another type on the right and says there is a mismatch.
Sort of the same as: int i = "ASTRING";
Can you post a small program that will compile and give the error you are getting. What you've posted is missing too many parts.
- 06-20-2011, 08:56 AM #7
Member
- Join Date
- Jun 2011
- Posts
- 4
- Rep Power
- 0
Thanks, it is works now.
You are right. The cause to this problem was at ALVertex class.
Java Code:private class ALVertex implements Vertex<V>{ private V element; //private ArrayList<[COLOR="red"]ALEdge[/COLOR]> edges = new ArrayList<ALEdge> private ArrayList<Edge<E>> edges; = new ArrayList<ALEdge>(); public ALVertex(){ edges = new ArrayList<ALEdge>(); } .... public ArrayList<ALEdge> getEdges(){ return edges; } ..... }
Thank you very much,
Kurs,.
- 06-20-2011, 03:32 PM #8
Try compiling it with jdk1.7 -> Much more info in the warning/error message:
Running: D:\Java\jdk1.7.0\bin\javac.exe -Xlint -g -deprecation -classpath D:\JavaDevelopment\;. IteratorProblem.java
IteratorProblem.java:16: warning: [rawtypes] found raw type: IteratorProblem.ALVertex
ALVertex vertex = null; //check(v);
^
missing type arguments for generic class IteratorProblem.ALVertex<V>
where V is a type-variable:
V extends Object declared in class IteratorProblem.ALVertex
IteratorProblem.java:19: warning: [unchecked] unchecked conversion
Iterator<Edge<E>> iter = vertex.getEdges().iterator();
^
required: Iterator<Edge<E>>
found: Iterator
where E is a type-variable:
E extends Object declared in class IteratorProblem.AdjacencyListGraph
IteratorProblem.java:67: warning: [rawtypes] found raw type: IteratorProblem.ALEdge
private ArrayList<ALEdge> edges = new ArrayList<ALEdge>();
^
missing type arguments for generic class IteratorProblem.ALEdge<E>
where E is a type-variable:
E extends Object declared in class IteratorProblem.ALEdge
IteratorProblem.java:67: warning: [rawtypes] found raw type: IteratorProblem.ALEdge
private ArrayList<ALEdge> edges = new ArrayList<ALEdge>();
^
missing type arguments for generic class IteratorProblem.ALEdge<E>
where E is a type-variable:
E extends Object declared in class IteratorProblem.ALEdge
IteratorProblem.java:69: warning: [rawtypes] found raw type: IteratorProblem.ALEdge
public ArrayList<ALEdge> getEdges(){
^
missing type arguments for generic class IteratorProblem.ALEdge<E>
where E is a type-variable:
E extends Object declared in class IteratorProblem.ALEdge
5 warnings
6 error(s)
Similar Threads
-
Graph Problem Java Directed
By daxter in forum Advanced JavaReplies: 4Last Post: 05-05-2011, 03:00 AM -
Graph in Jsp
By monika in forum New To JavaReplies: 0Last Post: 04-20-2010, 05:47 PM -
ECG Graph
By bharath333 in forum Java AppletsReplies: 4Last Post: 02-14-2009, 10:26 PM -
Help with graph's bar
By coco in forum Java 2DReplies: 1Last Post: 08-07-2007, 07:44 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks