Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 26th, 2005, 11:31 AM   #1
pr0gm3r
Hobbyist Programmer
 
Join Date: Dec 2004
Location: CA
Posts: 102
Rep Power: 4 pr0gm3r is on a distinguished road
Send a message via MSN to pr0gm3r
Post Unable to insert data to link list

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
pr0gm3r is offline   Reply With Quote
Old Sep 26th, 2005, 12:46 PM   #2
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
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 !
xavier is offline   Reply With Quote
Old Sep 26th, 2005, 1:35 PM   #3
pr0gm3r
Hobbyist Programmer
 
Join Date: Dec 2004
Location: CA
Posts: 102
Rep Power: 4 pr0gm3r is on a distinguished road
Send a message via MSN to pr0gm3r
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
pr0gm3r is offline   Reply With Quote
Old Sep 27th, 2005, 12:12 PM   #4
pr0gm3r
Hobbyist Programmer
 
Join Date: Dec 2004
Location: CA
Posts: 102
Rep Power: 4 pr0gm3r is on a distinguished road
Send a message via MSN to pr0gm3r
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
pr0gm3r is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 11:11 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC