I have a Person class, a Name class, and a demo. What i need is to call a method from the Person class that calls a method from the Name class for the demo. Heres an example:
Java starts variables with lower case letters. Which makes it clearer whether you are using the class Name or the variable name.
You are getting the NullPointer because Person never instantiates name. You want to create a setter in the Person class like public void setName(Name n) { name = n): }. Then your tester class can pass in a Name object.
Oh yeah, i didnt include that in my code example, oops. While i do have a set method, im trying a couple ways shown below, but still get a nullpointer. What else am i missing?
You've succeeded in moving the NullPointer to your set method. But Person still doesn't instantiate Name. So it is null when you try to update it in the setter. You need to call new Name() in the Person constructor.