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

Java null pointer exception - OnClick method

I am working on the Implementing Designs for Android course and have come across a bug in my code. I get a null pointer exception whenever I sign In, but not when I sign up. I don't think I am returning a null value, however it may be so.

The exception: https://gist.github.com/soush915/309492b1872a50273364

THe OnClickListener for the Sign In Button: https://gist.github.com/soush915/cba23f088da37a84f90b

3 Answers

Can you check if all of the referenced objects you use do exist when you call them in the login proccess? (mUsername and mPassword are being created before the click event is called?)

Also check Line 55 of your loginActivity

Line 55 is password.trim()

Also, the nullPointerException shows up immediately when I start the app. The app will still run but when I try to login, it will crash.

Have you seen the reference to the objects I spoke?

Turns out when I was refactoring the EditTexts into a layout, I removed the id for passwordField.

Glad I could help ;)

Also triming a null string will give you a nullPointer exception. Are you using a blank password for testing?