Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-18-2007, 05:49 PM
Member
 
Join Date: Jul 2007
Posts: 35
silvia is on a distinguished road
Error: cannot find symbol
Please i need help.

Code:
class Node { public Object data; public Node next; public Node() { this.data = null; this.next = null; } public Node(Object a) { this.data = a; this.next = null; } public Node(Object a, Node b) { this.data = a; this.next = b; } }
Code:
public class List { private Node head; private Node tail; public List() { this.head = null; this.tail = null; } public void insertAtFront(Object obj) { if (this.size()==0) { Node n = new Node(obj); this.head = n; this.tail = n; } else { Node n = new Node(obj); n.next = this.head; this.head = n; } } public void insertAtBack(Object obj) { if (this.size()==0) { Node n = new Node(obj); this.head = n; this.tail = n; } else { Node n = new Node(obj); this.tail.next = n; this.tail = n; } } public Object removeFromFront() { if (this.size()==0) { System.out.println("No data to remove."); return null; } else if (this.size()==1) { Object a = this.head.data; this.head = null; this.tail = null; return a; } else { Object a = this.head.data; this.head = this.head.next; return a; } }
Code:
public void insertAtSorted(String s) { if (this.size()==0) { insertAtFront(s); return; } else if (s<=this.head)// stuck on these type of statements { insertAtFront(s); return; } else if (s>=this.tail) // how to make so this works? <---------- { insertAtBack(s); return; } else { Node ntlnode = this.head; while (ntlnode.next <= s) { ntlnode = ntlnode.next; Node blah = new Node(s); blah.next = ntlnode; this.next = blah; } } }
Code:
public Object removeFromBack() { if (this.size()==0) { System.out.println("No data to remove."); return null; } else if (this.size()==1) { Object a = this.tail.data; this.head = null; this.tail = null; return a; } else { Object a = this.tail.data; Node ntlnode = this.head; while (ntlnode.next != this.tail) { ntlnode = ntlnode.next; } this.tail = ntlnode; this.tail.next = null; return a; } } public boolean isEmpty() { return this.head == null; } public void print() { if (this.size()==0) { System.out.println("Empty list!"); return; } Node curr = this.head; while (curr != null) { System.out.println(curr.data.toString()); curr = curr.next; //move forward to the next data item. } System.out.println(); } public int size() { int count = 0; Node curr = this.head; while (curr != null) { count++; curr = curr.next; } return count; } }
The error is:

Code:
List.java:100: operator <= cannot be applied to java.lang.String,java.lang.Object else if (s<=this.head.data) //not sure about this format of object<--------------- ^ List.java:105: operator >= cannot be applied to java.lang.String,java.lang.Object else if (s>=this.tail.data) ^ List.java:113: operator <= cannot be applied to Node,java.lang.String while (ntlnode.next <= s) ^ List.java:118: cannot find symbol symbol : variable next location: class List this.next = blah; ^ 4 errors
Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-07-2007, 06:39 AM
Member
 
Join Date: Jul 2007
Posts: 40
barney is on a distinguished road
Code:
java.lang.String,java.lang.Object else if (s<=this.head.data) //not sure about this format of object<---------------
Ok, I'm rusty on my Java but I'm pretty sure you can't use the operators on strings. As well, when comparing two things, they must be of the same type. So we can't compare a string to an object. So let's try something else...

//This converts the Object data to a string and then compares it to s
Code:
elseif(s.compareTo(this.head.data) <= 0)
//This does the same as the above to my knowledge, but explicitly casts the Object to a string
Code:
elseif(s.compareTo((String)this.head.data) <= 0)
Thus, for the other one, change head to tail and <= to >=
Greetings.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Java Error: Cannot find Symbol... bobleny New To Java 8 04-15-2008 07:35 AM
Programm Error: cannot find symbol Help? junix New To Java 2 12-10-2007 06:30 AM
cannot find symbol class error po0oker New To Java 5 10-31-2007 03:52 PM
Error: cannot find symbol cachi AWT / Swing 1 08-06-2007 09:12 PM
Error: cannot find symbol constructor zoe New To Java 1 07-24-2007 09:24 PM


All times are GMT +3. The time now is 12:29 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org