Results 1 to 9 of 9
Thread: Linked List Help
- 08-08-2011, 01:12 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 8
- Rep Power
- 0
Linked List Help
Hi I am new to Java and am trying to implement a Linked List in my program that reads from a text file(external source).
Here is the code I have typed, I have got an error saying cannot find symbol Property within my java program. The external text file is called Property.txt, if anyone could guide me as to what I have done wrong I would appreciate it.
Java Code:public static void main (String[]args) { PropertyManager myManager = new PropertyManager(); myManager.setVisible(true); myManager.setSize(new Dimension(750, 600)); LinkedList<String> property = new LinkedList<String>(); int size = property.size(); for(int i=0;i<property.size();++i) { property.add("463,Sold,James Smith,12/01/10,14 River road Norman Gardens Q4701"); property.add("118,Sale,Arthur London,20/01/10,51 Coast street Frenchville Q4701"); property.add("200,Deposit taken,Scott Jones,30/01/10,11 Airport road Rockhampton Q4700"); property.add("129,offer received,Andy Roberts,05/12/09,9 South avenue Rockhampton Q4700"); property.add("123,Sale,Joshua Lincoln,15/12/09,3 Mackay road Frenchville Q4701"); property.add("124,Sale,Michael Green,12/12/10,33 Georginia court Glenlee Q4701"); property.add("167,under contract,Peter Lee,11/09/10,14 Friendly drive Glenmore Q4701"); property.add("201,Sold,Euller Patel,22/01/11,5 Sunrise avenue Norman Gardens Q4701"); property.add("500,Sale,Kim Johnson,19/12/10,87 Bluesky court Rockhampton Q4702"); Property p = (Property)property.get(i); } } //main
I:\PropertyManager.java:211: error: cannot find symbol
Property p = (Property)property.get(i);
^
symbol: class Property
location: class PropertyManager
I:\PropertyManager.java:211: error: cannot find symbol
Property p = (Property)property.get(i);
^
symbol: class Property
location: class PropertyManager
2 errors
Tool completed with exit code 1
Please excuse me if the error is so simple, if it is I apologize as I am really new to Java and have based most of my code from a book that I have been studying.Last edited by sneeak; 08-08-2011 at 01:17 PM.
- 08-08-2011, 01:35 PM #2
Where is the class Property defined? The compiler can not find its definition.
You need to add code to define a class name Property.
- 08-08-2011, 01:37 PM #3
Member
- Join Date
- Aug 2011
- Posts
- 8
- Rep Power
- 0
Ok so i think I made a typo its now: PropertyManager p = (PropertyManager)property.get(i);
^
I am getting an error that says..
java:126: error: inconvertible types
It says something about casting wrong?
What would I have to do to fix the error?Last edited by sneeak; 08-08-2011 at 01:42 PM.
- 08-08-2011, 01:45 PM #4
Which variables are the incompatible types?
What type does the get() method return?
When posting error messages, please post the FULL text of the error message. Don't leave parts of it off.
- 08-08-2011, 02:06 PM #5
Member
- Join Date
- Aug 2011
- Posts
- 8
- Rep Power
- 0
That is the error message the little arrow is pointing at get(i);
I:\PropertyManager.java:130: error: inconvertible types
PropertyManager p = (PropertyManager)property.get(i);
^
required: PropertyManager
found: String
1 error
Tool completed with exit code 1
and I havent set a return method for get() I dont think
- 08-08-2011, 02:10 PM #6
The get() method is for the LinkedList<String> object. That class defines what get() returns.I havent set a return method for get()
What value do you expect to "get" from the property object? It contains Strings.
- 08-08-2011, 03:57 PM #7
Member
- Join Date
- Aug 2011
- Posts
- 8
- Rep Power
- 0
Sorry wasnt at PC, i expect to get a string from a string within a textfile and then compare it with a string entered in a textfield, which when the button is pressed it compares the string to the textfile to the one entered in the textfield, then displays it in the second textarea.
- 08-08-2011, 04:02 PM #8
What is the purpose of the above?Java Code:PropertyManager p = (PropertyManager)property.get(i);
You last post#7 says that you are working with Strings. It says nothing about the PropertyManager class.
- 08-08-2011, 04:36 PM #9
Member
- Join Date
- Aug 2011
- Posts
- 95
- Rep Power
- 0
If it did compile, it wouldn't do anything, as it would never get into the loop. (Heck; it wouldn't even throw a ClassCastException. ;-)
It might make more sense to do things in this order:
Java Code:LinkedList<String> property = new LinkedList<String>(); property.add("463,Sold,James Smith,12/01/10,14 River road Norman Gardens Q4701"); property.add("118,Sale,Arthur London,20/01/10,51 Coast street Frenchville Q4701"); property.add("200,Deposit taken,Scott Jones,30/01/10,11 Airport road Rockhampton Q4700"); property.add("129,offer received,Andy Roberts,05/12/09,9 South avenue Rockhampton Q4700"); property.add("123,Sale,Joshua Lincoln,15/12/09,3 Mackay road Frenchville Q4701"); property.add("124,Sale,Michael Green,12/12/10,33 Georginia court Glenlee Q4701"); property.add("167,under contract,Peter Lee,11/09/10,14 Friendly drive Glenmore Q4701"); property.add("201,Sold,Euller Patel,22/01/11,5 Sunrise avenue Norman Gardens Q4701"); property.add("500,Sale,Kim Johnson,19/12/10,87 Bluesky court Rockhampton Q4702"); int size = property.size(); for(int i=0;i<property.size();++i) { String p = (String)property.get(i); System.out.println(p); }
Similar Threads
-
How to access an element of a linked list inside another linked list?
By smtwtfs in forum New To JavaReplies: 4Last Post: 02-21-2011, 09:34 AM -
Need help using linked list
By tigertomas in forum New To JavaReplies: 5Last Post: 02-12-2011, 03:22 PM -
Linked list inside a linked list
By viperlasson in forum New To JavaReplies: 5Last Post: 07-26-2010, 11:15 PM -
Need help in linked list
By Hotzero in forum New To JavaReplies: 17Last Post: 06-05-2010, 08:13 AM -
Linked List integer list
By igniteflow in forum Advanced JavaReplies: 1Last Post: 12-10-2008, 08:53 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks