Results 1 to 6 of 6
  1. #1
    filipek is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Question Another cannot find symbol variable thread

    Good afternoon,
    My assignment is due tonight, and Im running into some problems with the Java compiler. This is my code:

    public class DoublyLinkedList<T> implements SimpleList<T> {

    protected Node dummy;
    protected int n;
    public DoublyLinkedList() {

    dummy = new Node();
    dummy.next = dummy;
    dummy.pre = dummy;
    n = 0;
    throw new NotYetImplementedException();
    }

    public void addFirst(T o) { throw new NotYetImplementedException(); }

    public void addLast(T o) { throw new NotYetImplementedException(); }

    public void add(int index, T element){ throw new NotYetImplementedException(); }

    public T getFirst() { throw new NotYetImplementedException(); }

    public T getLast() { throw new NotYetImplementedException(); }

    public T get(int index) { throw new NotYetImplementedException(); }

    public void clear() { throw new NotYetImplementedException(); }

    public T remove(int index){ throw new NotYetImplementedException(); }

    public boolean remove(Object o){ throw new NotYetImplementedException(); }

    public T removeFirst() { throw new NotYetImplementedException(); }

    public T removeLast() { throw new NotYetImplementedException(); }

    public T set(int index, T element){ throw new NotYetImplementedException(); }

    public int size() { throw new NotYetImplementedException(); }

    public boolean contains(Object o){ throw new NotYetImplementedException(); }

    public int indexOf(Object o){ throw new NotYetImplementedException(); }

    }

    public class Node<T> {

    public Node() {
    Node pre;
    Node next;
    T data;
    }


    }

    I want to use a dummy node in my implementation of the Doubly Linked List, so it will be easier to code all the methods I need to write.
    I keep on getting a problem with line 14 and 15:
    dummy.next = dummy;
    dummy.pre = dummy;
    // cannot find symbol variable next (compiler error)
    // cannot find symbol variable pre

    I haven't programmed for a while, I know I made some newbie mistake. Thanks in advance,
    Mark.

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    757
    Rep Power
    8

    Default Re: Another cannot find symbol variable thread

    You've declared the next and pre as local variable in the Node class constructor. So it won't available / accessible from outside the constructor.

  3. #3
    filipek is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default Re: Another cannot find symbol variable thread

    I've changed the code of the Node class:

    public class Node<T> {

    public Node() {
    Node pre;
    Node next;
    T data;
    }


    }


    to

    public class Node<T> {

    Node pre;
    Node next;
    T data;



    }


    and it compiles now. I think that was the solution. Thanks for quick reply

  4. #4
    filipek is offline Member
    Join Date
    Jun 2012
    Posts
    3
    Rep Power
    0

    Default Re: Another cannot find symbol variable thread

    I have another little problem now:

    public T getFirst() {

    return dummy.next.data; //error on this line
    }

    returns an error like this: 'incompatible types'

    This is the code for a Node:

    public class Node<T> {


    Node pre;
    Node next;
    T data;



    }

    Thanks in advance. Mark

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,188
    Rep Power
    19

    Default Re: Another cannot find symbol variable thread

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    pyler is offline Member
    Join Date
    Jul 2012
    Posts
    18
    Rep Power
    0

    Default Re: Another cannot find symbol variable thread

    The nodes inside your node class don't have types/aren't generic. The data variable is the only variable declared as a T type. Your nodes need to have the same type as your data variable so that you don't get incompatible type error.

Similar Threads

  1. Cannot find symbol variable
    By xalebo in forum New To Java
    Replies: 4
    Last Post: 11-28-2011, 07:09 PM
  2. Cannot find symbol variable Keyboard...
    By Alnegar in forum New To Java
    Replies: 6
    Last Post: 10-30-2010, 05:39 PM
  3. Java cannot find symbol- variable img
    By crutchfieldj in forum New To Java
    Replies: 3
    Last Post: 04-13-2010, 10:47 PM
  4. Cannot find symbol variable - Why? I can.. ^^
    By Mattedatten in forum New To Java
    Replies: 4
    Last Post: 03-08-2010, 07:07 PM
  5. Cannot find symbol variable pD! I cant fix it!!!
    By Addez in forum New To Java
    Replies: 2
    Last Post: 09-17-2009, 08:32 PM

Posting Permissions

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