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

Interactive Story challenge question: mSpaceship to Spaceship help.

First here is the url for the question: http://teamtreehouse.com/library/build-an-interactive-story-app/finishing-the-user-interface/using-a-model-in-the-controller

this is the additional code I've written(which is directly after insert code here):

mSpaceship = new Spaceship(); mSpaceship("FIREFLY");

I tells me you are setting mSpaceship in the onCreate method. Any help getting me in the right direction would be appreciated.

Thanks!

1 Answer

Hello,

One part of your Spaceship.java file contains:

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

This means that one of the constructors for the Spaceship class accepts a String as a parameter, which will then be used to set the mType for that object.

So, when you want to instantiate the mSpaceship object, you can pass in a String which will be set as the type like so:

mSpaceship = new Spaceship("FIREFLY");

The type for mSpaceship will now be "FIREFLY" and you wouldn't have needed to call a "setType()" method in a second line.