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) Finishing the User Interface Formatting Strings

l need help on the task 1

The LandingActivity interacts with the Spaceship model object we created. Start by setting mSpaceship to a new Spaceship object in the onCreate() method. Use the custom constructor that takes a String parameter, and pass in "FIREFLY" as the parameter

4 Answers

Just 1 line of code

mSpaceship = new Spaceship("FIREFLY");

The Spaceship class has 2 constructors, 1 is just a default constructor that does not take any parameter. The other one takes a string parameter.

When you call new Spaceship("FIREFLY"); you call the second constructor and passed in the string.

spaceship = new Spaceship("FIREFLY");

public class Spaceship { private String mType; private int mNumPassengers = 0;

public String getType() {
  return mType;
}

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

public int getNumPassengers() {
  return mNumPassengers;
}

public void setNumPassengers(int numPassengers) {
  mNumPassengers = numPassengers;
}

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

public Spaceship(String type) {
  mType = type; 
  mSpaceship = new Spaceship("FIREFLY");
}

} am getting an error where am i wrong

SIBONGILE CHIROPA, you have chosen the wrong file.

It goes in the file named: LandingActivity.java

On this file : LandingActivity.java

//add this code mSpaceship = new Spaceship("FIREFLY");