Results 1 to 8 of 8
  1. #1
    kursist is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default 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

    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;
    		}
    ....
    }
    Adv.
    Thanks
    Last edited by kursist; 06-19-2011 at 02:04 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    but it gives error. Some type missmatch
    When you get errors, please copy and paste here the full text of the error message. That will speed things up.

    Also please surround your code with code tags. See: http://www.java-forums.org/misc.php?do=bbcode#code

  3. #3
    kursist is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default Thanks for replay.

    Quote Originally Posted by Norm View Post
    When you get errors, please copy and paste here the full text of the error message. That will speed things up.

    Also please surround your code with code tags. See: BB Code List - Java Forums

    Here is what it says. I use eclipse. ALEdge is inner class and it implements Edge<E>.


    Type mismatch: cannot convert from Iterator<AdjacencyListGraph<V,E>.ALEdge> to Iterator<Edge<E>>


    Thanks,
    kurs

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    cannot convert from Iterator<AdjacencyListGraph<V,E>.ALEdge> to Iterator<Edge<E>>
    Is that true? Can you convert the one type to the other? The compiler doesn't see how to do it.

    Your posting of the error didn't show the source line that caused the error.

  5. #5
    kursist is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    Is that true? Can you convert the one type to the other? The compiler doesn't see how to do it.

    Your posting of the error didn't show the source line that caused the error.
    The code is here. Cast doesn't work.
    Edge<E> is interface and the ALEdge is the implementation.




    Java Code:
    public Iterator<Edge<E>> incidentEdges(Vertex<V> v)
    	{
    		ALVertex vertex = check(v);
    		[B]Iterator<Edge<E>> iter = vertex.getEdges().iterator();[/B]
                    return  iter;
    	}
    Last edited by kursist; 06-19-2011 at 02:30 PM.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    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.

  7. #7
    kursist is offline Member
    Join Date
    Jun 2011
    Posts
    4
    Rep Power
    0

    Default Thanks, it is works now.

    Quote Originally Posted by Norm View Post
    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.

    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,.

  8. #8
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,516
    Rep Power
    25

    Default

    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

  1. Graph Problem Java Directed
    By daxter in forum Advanced Java
    Replies: 4
    Last Post: 05-05-2011, 03:00 AM
  2. Graph in Jsp
    By monika in forum New To Java
    Replies: 0
    Last Post: 04-20-2010, 05:47 PM
  3. ECG Graph
    By bharath333 in forum Java Applets
    Replies: 4
    Last Post: 02-14-2009, 10:26 PM
  4. Help with graph's bar
    By coco in forum Java 2D
    Replies: 1
    Last Post: 08-07-2007, 07:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •