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 trialArthur Kharzamanov
5,414 PointsI am a bit confused when we need to declare a private member variable and when to create a new object;
Hello everyone,
So now that I made a mistake of just creating a private member variable mColorWheel of type ColorWheel and calling getColor method with that variable which caused a runtime error: NullPointerException : Attempt to invoke virtual method 'java.lang.String com.example.akboss.funfacts.FactBook.getFact()' on a null object reference.
I am a little confused about when object creation is required.
Why was it so crucial to create a new ColorWheel object and to then use it to call the getColor() method? I know I learned this in the Java course and it should be simple yet once I put it to practice I got confused.
If someone could explain to me the reason for the NullPointerException I got and why an new object must have been created, I would appreciate it.
Thank you!