• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Paul Clapham
  • Devaka Cooray
  • Bear Bibeault
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Liutauras Vilda
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Piet Souris
Bartenders:
  • salvin francis
  • Carey Brown
  • Frits Walraven

I have a ClassCastException as well

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I run my client server project I am getting a ClassCastException error??? My method finds an employee by the ID, Here are the specs I am to use.
variables
ArrayList emps;
Employee emp; I have an Employee class
Test the map for the passed key
if found
set the emps var to the arraylist found by doing a get on the byId map using the passed arg
extract the one employee outof the map using the map's get(0) method
execute the employees toString() to represent this emp as a string and return the stringto the protocol
otherwise return string that says not found

here is the code:

 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which line throws the exception? What exactly does it say? Usually the message will identify what class you were attempting to cast to, and what class was actually found. This is really useful information when debugging; don't overlook it.
 
mike hengst
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is an updated code version, same error:
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you're adding an ArrayList to an ArrayList, then taking it out and expecting it to have magically transformed into an Employee?
 
mike hengst
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hows this:
It still does not work???
 
mike hengst
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have somewhat figured out??? However data is not displaying correctly. Can you look at this please, thank you. Here are the pertinent methods

 
Ranch Hand
Posts: 218
VI Editor Ruby Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mike,
When you said the data was not displayed right,
how do you want it display and how was it displayed currently?
-Ryo
 
Men call me Jim. Women look past me to this tiny ad:
ScroogeXHTML 8.7 - RTF to HTML5 and XHTML converter
https://coderanch.com/t/730700/ScroogeXHTML-RTF-HTML-XHTML-converter
    Bookmark Topic Watch Topic
  • New Topic