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 trialtshuutheniemvula
7,251 Points*QUESTION FOR MODS, STAFF OR PRO* Ribbit NullPointer in UserAdapter at String email = user.getEmail().toLowerCase();
Hi all,
THIS IS A QUESTION FOR MODS, STAFF OR PRO
So a year later and I still have not managed to solve this issue, for detailed explanations please refer to
https://teamtreehouse.com/community/ribbit-null-pointer-at-user-adapter-2
and
https://teamtreehouse.com/community/editfriendsactivity-wont-open-in-ribbit-application
Stacktrace points to NullPointer but can't quite catch the bug. Seems to happen in a superclass and I don't know how to bury far enough into them.
App crashes at String email = user.getEmail().toLowerCase(); in UserAdapter
If line is omitted app works but gridView ends up getting messed up and not listing users in correct manner/sporadic crashes.
Please any help?
5 Answers
Steve Hunter
57,712 PointsHi there,
Do you have your code in version control in a remote repo? If you can push it up into GitHub, I can replicate the error at this end and try and find a fix.
Steve.
Steve Hunter
57,712 PointsI'm getting an error when I sign up for a new account.
https://goo.gl/photos/b8bnHaEwrz7Ri3ap9
I then get an error when I try to browse to add friends - that just gives me the 'has stopped' thing. That's the same error - java.lang.String cannot be cast to org.json.JSONObject
Steve Hunter
57,712 PointsProcess: com.thetechguys.penamoroo1p3, PID: 2139 java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.String.toLowerCase()' on a null object reference at com.thetechguys.penamoroo1p3.adapters.UserAdapter.getView(UserAdapter.java:55)
Steve Hunter
57,712 PointsThe issue seems to be that a user
doesn't have an email? The user
object is populating, but the email isn't.
Where's all that defined?
Steve Hunter
57,712 PointsYour edit friends isn't working right - where you click is not the same as where the tick occurs. That could cause a cross-over with nulls.
tshuutheniemvula
7,251 PointsHi Steve,
are you commenting out the String email = user.getEmail().toLowerCase(); to get it running? I looked at my EditFriends code and it could have been a syntax mistake in the onItemClickListener which I made some changes to although this does not fix my issue as I still cannot list friends.
The email is set during sign up and I can definately see them on my Parse dashboard, I don't know why they aren't populating when users is polled.
Steve Hunter
57,712 PointsI'm just running the code as is. I have made no amendments.
I get some errors but the app runs.
Steve Hunter
57,712 PointsWhat emulator are you using and what SDK level?
tshuutheniemvula
7,251 PointsHi Steve, so the issue does seem to be user related. Seems if a user has over 5 friends, app crashes while attempting to list them. I'm compiling in 19, 23 build tools and 15 minimum. I'm rechecking EditFriends and FriendsFragment to check on the ticking issue. I also get the Java nullpointer at UserAdapter line 55, but it doesn't crash app anymore. Weird. I need to rebuild whole backend anywho as Parse is going down, might be some features have deprecated since Treehouse used it for lessons.
Steve Hunter
57,712 PointsI think the lack of alignment between where the user clicks to add a friend and the friend that actually gets added may be causing this. If I click way down the list, it selects/deselects friends at the top of the list, not where I clicked. Clicking near the top of the list may, therefore, point to a non-existent friend, generating a null pointer exception.
Yes, Parse changed what services it offered some time ago. There will be significant differences. However, leave Parse as-is for now. Get the view working properly first. Change one thing at a time, and assume nothing. Don't go changing loads as that'll not help solve the problem! I don't think it is as simple as having 5 friends - I think it depends where those friends are listed. Get that clear issue fixed first - we can see that working, or otherwise. Then let's see whether that works or not.
tshuutheniemvula
7,251 PointsHi Steve,
So there was a syntax/typo issue with the onItemClicked method in EditFriends that was causing the wonky selection but that wasn't the cause of the main crash as I could log in with another user and add/remove friends even with the wonky selection but that's fixed now. I also fixed the null pointer error although I still don't have the specific cause. I am now additionally checking whether user.getEmail() is !=null before converting it to a string in UserAdapter and that seemed to do the trick.
tshuutheniemvula
7,251 Pointstshuutheniemvula
7,251 PointsHi Steve,
So I've modified it quite a bit. It's bit messy.
https://github.com/BecomingPhill/PenamOroo3
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsI'm cloning your project now ...