Solved

Java error ClassCastException

Posted on 2013-05-14
14
430 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 16

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
 
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 8

Expert Comment

by:stmani2005
ID: 39164095
i agree with cehj

getfieldvalue method not found in dsrequest class
0
 
LVL 16

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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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 16

Assisted Solution

by:krakatoa
krakatoa earned 166 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 167 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 16

Expert Comment

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

Assisted Solution

by:Valeri
Valeri earned 167 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 77
eclipse package explorer vs project explorer view 2 74
JList custom Cell Renderer refresh 15 53
How can I   ajax html table  rows? 20 60
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

919 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now