This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Java in General and the fly likes ClassCastException is occuring. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ClassCastException is occuring." Watch "ClassCastException is occuring." New topic

ClassCastException is occuring.

Huzefa Zohaib
Ranch Hand

Joined: Nov 21, 2001
Posts: 40
ClassCastException is occuring during execution of the following code.
Please solve this RunTimeError.

I am writing the object to the text file using the following code.
Mani Ram
Ranch Hand

Joined: Mar 11, 2002
Posts: 1140

Are you trying to create an User object and serialize it using the above code?
It won't work this way, because what you are actually creating in the above statement is a String object. So you will get a ClassCastException when you try to cast it into an User object.
Try the following code

Quaerendo Invenietis
It is sorta covered in the JavaRanch Style Guide.
subject: ClassCastException is occuring.
jQuery in Action, 3rd edition