Solved

Java error ClassCastException

Posted on 2013-05-14
14
443 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

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

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…

695 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