• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please explain this unknown ClassCastException

 
sam liya
Ranch Hand
Posts: 1240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is my activity.xml file



this is my Leave.java class



when i run this code i am getting below error?

 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 95
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 95
C++ Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am sorry:

In line 35..................
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic