Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSage Elliott
30,003 PointsOnclick Listener Crashes app
Hello, I am having a problem. Every time i add the onclick listener code shown in the video the app crashes when I try to run it. there is of course more code now initially in the main activity file than shown in the video. Im curious if that has something to do with it? I'm also having the same issue following other android tutorials on youtube.
Does anyone know of a common problem that would be causing this?
I will add the code in a separate comment in a bit.
5 Answers
Sage Elliott
30,003 PointsIncase you stumble upon the same issue, I added my solution here. https://teamtreehouse.com/forum/my-problemfix-for-adding-an-onclicklistener
Sage Elliott
30,003 PointsI have tried re-creating the file while watching the video several times before I decided I HAD to take to posting to the forum. Now when you start a new project in eclipse or any of the IDE it seems that you have to do most the XML editing in "fragment_main" rather than the "activity_main.xml" shown in the video, but everything thing works fine until I add in the onclick listener.
Thank you for your time viewing my question and I hope you can help a java me out, so I can pay it forward in the future!
Braden Ripple
Courses Plus Student 5,631 Pointsyeah I have the same problem, although it works when I call things that are inside my class but the problem occurs when I try to call stuff that are from other classes. However, when I call those same outside class methods without using the onclicklistener they still work...
Sage Elliott
30,003 PointsDid you see my post above? It has a link to what worked for me.
Braden Ripple
Courses Plus Student 5,631 Pointsyea, i know that'd work, it's just when I call methods from other classes using onClick(View v) or button.setOnClickListener(new OnClickListener) it still crashes
Sage Elliott
30,003 PointsSage Elliott
30,003 Points