Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

java.lang.IllegalStateException  RSS feed

 
Ranch Hand
Posts: 87
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.
 
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.
 
Rancher
Posts: 42975
76
  • 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: 87
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: 42975
76
  • 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: 87
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: 42975
76
  • 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.
 
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: 87
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: 42975
76
  • 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: 87
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!