?
Solved

Java error ClassCastException

Posted on 2013-05-14
14
Medium Priority
?
454 Views
Last Modified: 2013-05-15
Hello there,

what is wrong with this code. I get this error even though I cast it to Long or am I doing something wrong

java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Long

Users users = new Users();
users.setId((Long)dsRequest.getFieldValue("id"));

Open in new window


cheers
Zolf
0
Comment
Question by:zolf
  • 5
  • 4
  • 3
  • +2
14 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 39163879
Please post the class of which 'dsRequest' is an instance
0
 

Author Comment

by:zolf
ID: 39163888
0
 
LVL 17

Expert Comment

by:krakatoa
ID: 39163921
Looks pretty straightforward to me - getFieldValue() returns a String which you are trying to cast to Long, which can't happen.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Expert Comment

by:CEHJ
ID: 39164039
MIght be just me but i don't see a method of that name anywhere
0
 
LVL 9

Expert Comment

by:Manikandan Thiagarajan
ID: 39164095
i agree with cehj

getfieldvalue method not found in dsrequest class
0
 
LVL 17

Expert Comment

by:krakatoa
ID: 39164104
0
 

Author Comment

by:zolf
ID: 39164109
java.lang.Object getFieldValue(java.lang.Object fieldName)
           Returns the value for a particular fieldName.
0
 

Author Comment

by:zolf
ID: 39164111
Krakatoa

it returns an Object and takes an Object which I am passing a String and trying to cast it to long
0
 
LVL 17

Assisted Solution

by:krakatoa
krakatoa earned 664 total points
ID: 39164116
But not one that can be cast to Long evidently.

Check this method perhaps: getClientSuppliedCriteria
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39164130
java.lang.Object getFieldValue(java.lang.Object fieldName)
           Returns the value for a particular fieldName.
And the link to that method in the supplied javadoc is ..?
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 668 total points
ID: 39164133
users.setId(Long.valueOf(dsRequest.getFieldValue("id").toString()));

Open in new window

could be tried but is almost certainly unnecessary
0
 
LVL 17

Expert Comment

by:krakatoa
ID: 39164140
Show us the import statements from your code.
0
 
LVL 16

Assisted Solution

by:Valeri
Valeri earned 668 total points
ID: 39165159
this is what you have to write:
users.setId(Long.valueOf( (String) dsRequest.getFieldValue("id")));
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39167308
:)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question