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
Martin Stryffeler
1,744 PointsNull Pointer exception - ParseUser.getCurrentUser(); returns null
I'm doing the Ribbit project, on the part where you add the camera button options dialog - take picture, take video etc. When I run the app and tap the camera icon, the dialog box appears briefly, the app crashes, and the log displays this error:
Caused by: java.lang.NullPointerException at com.stryffeler.ribbit.EditFriendsActivity.onResume(EditFriendsActivity.java:52)
This is the code in the onResume() method of EditFriendsActivity.java at line 52.
51: mCurrentUser = ParseUser.getCurrentUser();
52: mFriendsRelation = mCurrentUser.getRelation(ParseConstants.KEY_FRIENDS_RELATION);
I don't know why this is a problem, because my app doesn't have trouble pulling friends lists from the server and editing them.
Thank you all for your help. Martin
3 Answers
Bryan Wiedeman
10,203 Pointswas an answer ever found for this?
Ben Jakuben
Treehouse TeacherWas your code working before? Can you add a log statement or debug to see if this method returns anything after a successful login?
Is everything else working as far as the current user is concerned? Like in MainActivity.java, what happens in this section of code?
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser == null) {
navigateToLogin();
}
else {
Log.i(TAG, currentUser.getUsername());
}
Martin Stryffeler
1,744 PointsYes I can get a log statement to verify a successful login, but the app does not remember the login, and I have to log in each time I run the app. ParseUser.getCurrentUser() must be returning a null in my MainActivity onCreate method as well.
Everything else in the app works as long as I don't tap the camera icon. I can look at friends lists, add and delete friends, and log in and out.
Ben Jakuben
Treehouse TeacherHmmm...I'm stumped! Can you zip up your code and email it to help@teamtreehouse.com? Mention me and it will get forwarded to me and I'll try to troubleshoot it myself.
Martin Stryffeler
1,744 Points.