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 trialKody Kendall
2,473 PointsNull Pointer Exception on mCurrentWeather object
I've seen a couple questions related to Null Pointer Exceptions, but not any specifically saying it's the mCurrentWeather object causing them.
Here's a line in the stack trace error I'm seeing:
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'double weather.android.kodyckendall.com.myweather.CurrentWeather.getHumidity()' on a null object reference.
Any thoughts? Do you think it's in the CurrentWeather class or the main? All the getters and setters are filled out appropriately.
Suleyman Orazgulyyev
Courses Plus Student 5,798 PointsHey! It may be that at the moment of calling that function don't have the Forecast yet, maybe there is no internet connection, or maybe you try to get the humidity before initializing your forecast. But as Steve said it's better to post the code :) at least the line where it's pointing to.
Steve Hunter
57,712 PointsSteve Hunter
57,712 PointsHi Kody,
Can you post your code, please?
The error trace will probably tell you which line initiated the error but it is likely to be where
getHumidity()
is being called. I'm guessing but it looks like whatever that method got called against is pointing at nothing.Let's have a look at your code and we can go from there. I'll open Studio so I can compare with my code, which is a little old now but might help!
Steve.