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

Android Build an Interactive Story App (Retired) The Model-View-Controller Pattern Adding a Custom Constructor

What is the error here?

Hi, I got this error java.lang.NullPointerException (Look around JavaTester.java line 100) while working on this challenge and I can't quite figure out what was wrong with it. The challenge was to set a custom constructor that uses a String parameter which is exactly what i did... can anyone please help?

Thank you.

P.S. If this is about the "use this parameter to make mType a specific kind of spaceship" then that's just vague wording of the challenge.

Spaceship.java
public class Spaceship {
    public String mType;

  public Spaceship(){
  mType = "SHUTTLE";
  }

  public Spaceship(String type1){

    type1 = mType;

  }

    public String getType() {
      return mType;
    }

    public void setType(String type) {
      mType = type;
    }
}

I think you should assign type1 to mType, not viseversa.

public Spaceship(String type1) {
mType = type1;
}

1 Answer

Hi Ariel,

You've assigned the argument to be mType instead of assigning mType to be the argument. Because mType has been initialized but not declared to be anything yet, it's "null"; assigning type1 to "point" to an undeclared variable is where that error message is coming from.

Hope that helps!