• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

OnClickListener is crashing the app. Need help!

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Saloon Keeper
Posts: 7597
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 598
26
Oracle Notepad Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Saloon Keeper
Posts: 7597
177
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 598
26
Oracle Notepad Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic