Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

OnClickListener is crashing the app. Need help!

 
Eric Sweeten
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I eliminated everything else that could be causing the problem. As soon as I attempt to add the instantiated listener, the app crashes. Here is my code:







No idea what's wrong. Any ideas?
 
Tim Moores
Bartender
Posts: 3134
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If an app crashes, then there should be a stack trace I the logcat; that includes details of the cause of the crash as well as the exact line of code. Post the full stack trace.
 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not believe you can instantiate ItemClickListener as a variable and also as a class.

To test and make sure it is the issue, remove both the variable and the method, and add Implements ItemClickListener to the Activity declaration. Use autocode (alt-enter) to implement the listener, and change the .setOnItemClickListener()s to use "this":

If that does not crash, it was the double declaration that caused the issue.
 
Tim Moores
Bartender
Posts: 3134
50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Tkatch wrote:I do not believe you can instantiate ItemClickListener as a variable and also as a class.
...
If that does not crash, it was the double declaration that caused the issue.

If there were two things of the same name, that would cause a compiler error, not a runtime error. But since the names are capitalized differently -and thus different from Java's point of view-, it should not cause a problem.
 
Brian Tkatch
Bartender
Posts: 567
25
Linux Notepad Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim Moores wrote:If there were two things of the same name, that would cause a compiler error, not a runtime error. But since the names are capitalized differently -and thus different from Java's point of view-, it should not cause a problem.


Oh, i didn't see that. I despise case sensitivity.

My test still stands though.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic