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 trial

Android

Miles Torres
Miles Torres
2,316 Points

What does this logcat error mean?

ComponentInfo{com.example.milespc.funfacts/com.example.milespc.funfacts.ActivityFunFacts}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference

Mazen Halawi
Mazen Halawi
7,806 Points

seems your button is not referenced correctly in your java code. check your id or paste your xml code of the button you are clicking and how you are referencing it in java.

another solution: add android:onClick="btnClick_onClick" in xml for that button // you can call the method whatever you want in java create a

public void btnClick_onClick(View v) {

}

and put your code inside to test.