Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 24th, 2006, 10:42 PM
cam cam is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 2 cam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 56 sec
Reputation Power: 0
Class Casting Problem

Hey all. I'm sure this is a simple problem, but it's killing me right now. I have a linked list full of linked lists, and I want to be able to set a linked list inside the list of linked lists. So, I'm trying to get from the larget linked list, cast the returned result as a linkedlist, and then set it, like so...

Code:
    public void setTeam(LinkedList aTeam, int teamIndex) {
        ( (LinkedList)(teams.get(teamIndex)) ).set(aTeam);
        
        LinkedList test = ( (LinkedList)(teams.get(teamIndex)) );
    }


This gives me a "cannot resolve symbol" error. The really frustrating thing is, it pukes on the first line of code, but the second is just fine, even though it's cast the same way! The only difference is, of course, the call to the set function of the newly cast linked list. Can anyone tell me what I'm doing wrong? Thanks in advance!

-Cameron

Reply With Quote
  #2  
Old January 25th, 2006, 07:25 AM
arunsudhir arunsudhir is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 4 arunsudhir User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 33 sec
Reputation Power: 0
Re: Class casting Problem

i guess the set method of LinkedList has two arguments... an integer specifying the index and the LinkedList object.. you have given only the latter..
Quote:
Originally Posted by cam
Hey all. I'm sure this is a simple problem, but it's killing me right now. I have a linked list full of linked lists, and I want to be able to set a linked list inside the list of linked lists. So, I'm trying to get from the larget linked list, cast the returned result as a linkedlist, and then set it, like so...

Code:
    public void setTeam(LinkedList aTeam, int teamIndex) {
        ( (LinkedList)(teams.get(teamIndex)) ).set(aTeam);
        
        LinkedList test = ( (LinkedList)(teams.get(teamIndex)) );
    }


This gives me a "cannot resolve symbol" error. The really frustrating thing is, it pukes on the first line of code, but the second is just fine, even though it's cast the same way! The only difference is, of course, the call to the set function of the newly cast linked list. Can anyone tell me what I'm doing wrong? Thanks in advance!

-Cameron

Reply With Quote
  #3  
Old January 25th, 2006, 07:26 AM
arunsudhir arunsudhir is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 4 arunsudhir User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 54 m 33 sec
Reputation Power: 0
try replacing the set line as:

( (LinkedList)(teams.get(teamIndex)) ).set(teamIndex,aTeam);

Quote:
Originally Posted by arunsudhir
i guess the set method of LinkedList has two arguments... an integer specifying the index and the LinkedList object.. you have given only the latter..

Reply With Quote
  #4  
Old January 25th, 2006, 09:57 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Click here for more information.
 
Join Date: Sep 2005
Posts: 704 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 2 Days 23 h 55 m 41 sec
Reputation Power: 4
If you still have problems, post your code please. LinkedList is not a standard java class but your own right?

I would recommend using arraylists with generics (java 1.5) by the way.

Reply With Quote
  #5  
Old January 25th, 2006, 05:46 PM
cam cam is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Posts: 2 cam User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 m 56 sec
Reputation Power: 0
Haha, I knew it'd be something stupid! I guess my mind kept thinking I'd already gotten what I needed, so I wouldn't need to tell set what it was (which, of course, makes no sense now that I actually think about it). How embarassing... Anyway, thanks for the help, guys.

And Icon, LinkedList is a standard Java class. It's in java.util, I believe.

Reply With Quote
  #6  
Old January 26th, 2006, 09:41 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Click here for more information.
 
Join Date: Sep 2005
Posts: 704 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 2 Days 23 h 55 m 41 sec
Reputation Power: 4
You're right, I was not sure about it anyway. Good luck

Reply With Quote
  #7  
Old January 26th, 2006, 09:47 AM
MadCowDzz's Avatar
MadCowDzz MadCowDzz is offline
I'm Internet Famous
Dev Articles Frequenter (2500 - 2999 posts)
 
Join Date: Jan 2003
Location: Toronto, Canada
Posts: 2,890 MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level)MadCowDzz User rank is Lance Corporal (50 - 100 Reputation Level) 
Time spent in forums: 1 Week 16 h 14 m 9 sec
Reputation Power: 8
Quote:
Originally Posted by Icon
If you still have problems, post your code please. LinkedList is not a standard java class but your own right?

I would recommend using arraylists with generics (java 1.5) by the way.

Go Tiger! =)
__________________
Daryl's Homepage | My Blogroll | My Profile | Firefox supporter!
DevArticles Forum Moderator

"The net is a waste of time, and that's exactly what's right about it." -- William Gibson

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Class Casting Problem


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT