• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting cast exception....

 
Nagendra Shasthri
Ranch Hand
Posts: 35
Chrome Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator




When I tried to execute this code I got exception:

exception: java.lang.ClassCastException: java.util.ArrayList cannot be cast to org.example.www.PatientDetails.List

How to resolve this?Is there any other methods to display data?Please guide me...

Thanks in advance....
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You've always got to be careful if you've got multiple classes with the same name.

I this case, it's taking the List declaration on line 4 to be org.example.www.PatientDetails.List, instead of java.util.List.

If you've got control over the other code, I'd suggest changing the name. Otherwise, using the fully-qualified name would fix it.
 
Nagendra Shasthri
Ranch Hand
Posts: 35
Chrome Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I take list of type org.example.www.PatientDetails I can't add the columns(like I have done on line 12 &13) to that list right?If I don't use java.util.List how to add the data comin fron resultset to list of type org.example.www.PatientDetails?
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No idea - I know nothing about that class - it's not part of core java and I was assuming it's part of your application. You need to decide which type of list you're working with, and stick with it. Why does the method not just return a java.util.List?

[Correction to my earlier post - I thought the error was happening on line 4, but you're probably getting when you cast to the return type on line 19. It's still a confusion between the types though. If you need to return a org.example.www.PatientDetails.List, then creating an ArrayList is no good.]
 
Nagendra Shasthri
Ranch Hand
Posts: 35
Chrome Java MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah...I am getting exception on line 19 while casting it...return type can't be java.util.List..Because in wsdl file if we give ooutput type as list the IDE generated skeleton of this class file had the return type org.example.www.PatientDetails.List....
 
Matthew Brown
Bartender
Posts: 4568
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might be better off declaring the return type in the WSDL as an array. java.util.List is a java specific feature, whereas the WSDL should be language independent.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!