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
Sousheel Vunnam
3,366 PointsJava 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
Nuno Neves
2,803 PointsCan 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?)
Sousheel Vunnam
3,366 PointsTurns out when I was refactoring the EditTexts into a layout, I removed the id for passwordField.
Nuno Neves
2,803 PointsGlad I could help ;)
Nuno Neves
2,803 PointsAlso triming a null string will give you a nullPointer exception. Are you using a blank password for testing?
Nuno Neves
2,803 PointsNuno Neves
2,803 PointsAlso check Line 55 of your loginActivity
Sousheel Vunnam
3,366 PointsSousheel Vunnam
3,366 PointsLine 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.
Nuno Neves
2,803 PointsNuno Neves
2,803 PointsHave you seen the reference to the objects I spoke?