File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Android and the fly likes please explain this unknown ClassCastException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "please explain this unknown ClassCastException" Watch "please explain this unknown ClassCastException" New topic
Author

please explain this unknown ClassCastException

sam liyanage
Ranch Hand

Joined: Nov 25, 2008
Posts: 1031
this is my activity.xml file



this is my Leave.java class



when i run this code i am getting below error?

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39535
    
  27
What kind of object is the code retrieving? And what kind of object is it trying to cast it to? And what kind of cast is the error message complaining about? Answer these 3 questions, and you should be on your way to solving the problem.

(I am surprised the code even builds. I wouldn't have thought that having multiple UI elements in one layout file with the same ID even works. At the least, it's majorly confusing. But that has nothing to do with the issue at hand - it's an additional problem.)


Ping & DNS - updated with new look and Ping home screen widget
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39535
    
  27
On taking a second look - what is the relationship between the code and the layout file? They don't seem to go together.
Naishadh Parmar
Ranch Hand

Joined: Jun 02, 2011
Posts: 95


On line 35: You are trying to get a view which is actually a LinearLayout and cast it to a Button. That is why you get a ClassCastException.
Naishadh Parmar
Ranch Hand

Joined: Jun 02, 2011
Posts: 95


I am sorry:

In line 35..................
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please explain this unknown ClassCastException
 
Similar Threads
how to handle different screen sizes
Layouts, bottom position
FrameLayout overlaps TextView
when i change android:orientation to horizontal it shows blank screen
set alpha of only parent