File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Problem With ClassCasting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Problem With ClassCasting" Watch "Problem With ClassCasting" New topic
Author

Problem With ClassCasting

mike hengst
Ranch Hand

Joined: Oct 19, 2002
Posts: 43
This is my problem:
if LastName map contains the key of this emp's lastname
extract the value object(an arraylist) from the map and add
the current emp object reference to it
else
instantiate a new arraylist and add the emp reference to it
then add the last name key and the arraylist value object
to the map
Here is what I have so far:

The problem is that when I run into the second instance of a last name(inmy case smith) it throws a ClassCastException on this line:
((ArrayList)byLast.get(emp.getLastName())).add(emp);
What should I do??? It does seem that this is the only forum that I can get serious answers to my problems and I truly appreciate that fact. So thatnk you to anyone who can help me straighten out my code.
[ April 07, 2003: Message edited by: mike hengst ]

Thank you Oh Lord<br />For the white blind light<br />A city rises from the sea<br />I had a splitting headache<br />from which the future's made<br />--morrisson
mike hengst
Ranch Hand

Joined: Oct 19, 2002
Posts: 43
I have solved the problem. It is adding everybody in now. Now onto the other errors. HA they nver end.
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
You are not going to share your solution?
Pleeeeeeeese?


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem With ClassCasting
 
Similar Threads
Understanding List.remove() and List.contains()
xml experts help me SAX Parser in xml
I have a ClassCastException as well
Problems w/ a HashMap
Passing an object back and forth between Client and Server!!!