![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
HI guys,
I need your experties in java. I tried to insert some integer numbers from a file to an UnorderedLinkList class which is derived from LinkListClass class. somehow the insertFirst(DataElement newItem) method in LinkListClass is not able to accept my data. Error msg said "uncompatible type" -> inserftFirst(DataElement) to (int), but I have a derived class from DataElemet. I have derived IntElemet from DataElement... below is the main functions: public static void main(String[] args)throws IOException
{
UnorderedLinkList listItem = new UnorderedLinkList();
IntElement num = new IntElement();
BufferedReader infile = new BufferedReader(new
FileReader("TestLab3.data"));
StringTokenizer tokenizer = new StringTokenizer(infile, " ");
while(infile != null){
num.setNum(Integer.parseInt(tokenizer.nextToken()));
listItem.insertFirst(num);
}
}I tried to create an ADT link list that will accept all kinds of data type. if you have any questions. please do not hesitate to ask. Thank you in advance.
__________________
-- pr0gm3r |
|
|
|
|
|
#2 |
|
Professional Programmer
|
I don't know about the linked list thing but . your reading from file ... i don't think it's going to work . Should be something like :
public static void main(String[] args)throws IOException
{
UnorderedLinkList listItem = new UnorderedLinkList();
IntElement num = new IntElement();
BufferedReader infile = new BufferedReader(new
FileReader("TestLab3.data"));
String line = "";
while((line = infile.readLine()) != null){
StringTokenizer tokenizer = new StringTokenizer(line, " ");
while(tokenizer.hasMoreTokens()){
num.setNum(Integer.parseInt(tokenizer.nextToken()) );
listItem.insertFirst(num);
}
}
}
__________________
Don't take life too seriously, it's not permanent ! |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
|
Thanks...sorry I forgot to put the infile bufferedReader to a string. btw I am writting it on top of my head... I am don't have my actuall code handy..
btw I am not sure why the DataElemet are not compatibe with int. I thought DataElement is a generic data type... thank you for all your help
__________________
-- pr0gm3r |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
|
I got it to work... Thank you for your help and suggestions....
error was ... I tried to convert int datatype to DataElement datatype... which is I suppose to derived IntElement class from DataElement. IntElement is a class that will manipulate int datatype. here is the full source code.. http://geocities.com/harry_tanama/Project.html
__________________
-- pr0gm3r |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|