Link to home
Start Free TrialLog in
Avatar of Zolf
ZolfFlag for United Arab Emirates

asked on

Java error ClassCastException

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
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Please post the class of which 'dsRequest' is an instance
Avatar of Zolf

ASKER

Looks pretty straightforward to me - getFieldValue() returns a String which you are trying to cast to Long, which can't happen.
MIght be just me but i don't see a method of that name anywhere
i agree with cehj

getfieldvalue method not found in dsrequest class
Avatar of Zolf

ASKER

java.lang.Object getFieldValue(java.lang.Object fieldName)
           Returns the value for a particular fieldName.
Avatar of Zolf

ASKER

Krakatoa

it returns an Object and takes an Object which I am passing a String and trying to cast it to long
SOLUTION
Avatar of krakatoa
krakatoa
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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 ..?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Show us the import statements from your code.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:)