• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

java.lang.IllegalStateException

 
Kovacs Akos
Ranch Hand
Posts: 86
1
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you think, what is the problem with this code?


ADT gives the error in the title.
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to post the entire stack trace to get more help here.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There should be more information (like the line number) in the stack trace in the logcat output. Without knowing which line of code causes this we'd just be poking in the dark.
 
Kovacs Akos
Ranch Hand
Posts: 86
1
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
James Boswell wrote:I think you need to post the entire stack trace to get more help here.


Here is the full code:

 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not the code - the stack trace of the error message.
 
Kovacs Akos
Ranch Hand
Posts: 86
1
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:Not the code - the stack trace of the error message.


Sorry:
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hm, not sure if the line numbers of the exception correspond with the line numbers of the code as shown here. Which of the toasts are shown?
 
James Boswell
Bartender
Posts: 1051
5
Chrome Eclipse IDE Hibernate
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This looks like the likely culprit:

10-22 05:49:38.147: E/AndroidRuntime(333): Caused by: java.lang.ClassCastException: android.widget.RelativeLayout

But I agree with Ulf, the line numbers don't match up.
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think it matters which line actually causes the exception, several lines in the method do the same thing: cast the view passed to the method to a TextView. Apparently the view passed in is actually a RelativeLayout, not a TextView and so can't be cast that way.

The view gets passed in from dont(), but we can't tell from this code where dont() gets the view - all we know is that the view is not a TextView as expected. You need to figure out where the view comes from and why it is a RelativeLayout rather than the expected type.
 
Kovacs Akos
Ranch Hand
Posts: 86
1
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Steve Luke wrote:I don't think it matters which line actually causes the exception, several lines in the method do the same thing: cast the view passed to the method to a TextView. Apparently the view passed in is actually a RelativeLayout, not a TextView and so can't be cast that way.

The view gets passed in from dont(), but we can't tell from this code where dont() gets the view - all we know is that the view is not a TextView as expected. You need to figure out where the view comes from and why it is a RelativeLayout rather than the expected type.



The Textviews are on a RelativeLayout layout.
Toasts are working after clicking on the textviews.
 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kovacs Akos wrote:The Textviews are on a RelativeLayout layout.

That doesn't answer Steve's question of where that "View v" comes from that you're passing into the "dont" method. If that's a RelativeLayout object, that would explain what's happening.
 
Kovacs Akos
Ranch Hand
Posts: 86
1
Firefox Browser Netbeans IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The onclicklistener was earlier in RelativeLayout, so yes that causes the error. Now I have move it to each textviews, one of them look like this:


Thanks, I have found the source of this problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic