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 trialJohn Emenecker
4,735 PointssetOnClickListener
I get a "Cannot resolve symbol 'setOnClickListener'" when I enter showFactButton.setOnClickListener();
I had to import the Button library to resolve another error, but am I missing a library. I don't see "set..." show up at all in the auto complete for the method.
1 Answer
Kevin Haube
12,265 PointsTry something like this.
final View.OnClickListener listener = new View.OnClickListener()
If you're using Android Studio, it'll prompt you to impliment the unused method and that will add the method needed to define what the listener will do. After the method, outside of its scope, declare your .setOnClickListener(listener);
If I had a peek at your code, I'd be able to help you with your specific problem. :) Be sure to update the question with a snippit of your code!
Fabian Claudio
4,017 PointsThanks Kevin I had the same problem and this solved it.
Ryan Duchene
Courses Plus Student 46,022 PointsRyan Duchene
Courses Plus Student 46,022 PointsDouble-check your code and compare it to the video, just to be safe. Also, can you paste your code here for us to see?