• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Problem With ClassCasting

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
mike hengst
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have solved the problem. It is adding everybody in now. Now onto the other errors. HA they nver end.
 
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are not going to share your solution?
Pleeeeeeeese?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic