Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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

Orla McGreal
Orla McGreal
1,625 Points

I keep getting this error : java.lang.NullPointerException at JavaTester.run(JavaTester.java:1

In the code challenge I keep getting this error

java.lang.NullPointerException at JavaTester.run(JavaTester.java:100) at JavaTester.main(JavaTester.java:39)

This is my code - could anyone show me where I am going wrong - I don't really understand the task....

public class Spaceship { public String mType; public String mShuttle;

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

public Spaceship (String MShuttle){ mShuttle ="Apollo 13"; }

Thanks so much in advance!!

1 Answer

You second constructor needs to set


to the the argument it receives. e.g.

public Spaceship (String type)
  mType = type;

The null pointer exception is likely causes by the test code calling your second construction and then trying to access mType to ensure it has been set. Since mType is still null it fails.

Orla McGreal
Orla McGreal
1,625 Points

Thank you so much it's beginning to all make sense!!!