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

mSpaceship.Spaceship(mSpaceship.Spaceship("FIREFLY"); doesn't work ? Can any one help

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.

2 Answers

Jack Middlebrook
Jack Middlebrook
19,745 Points

The code given to you in this Code Challenge only creates the variable mSpaceship that can hold an object of type Spaceship. In the first step you need to assign mSpaceship to a new Spaceship object. If you click to the Spaceship.java tab you can see that there is a constructor that you can pass a String to as follows:

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

Knowing this you can set mSpaceship to a new Spaceship object as follows:

mSpaceship = new Spaceship("FIREFLY");

where the String passed in the constructor is "FIREFLY".

import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText;

public class LandingActivity extends Activity {

public Button mThrustButton;
public TextView mTypeLabel;
public EditText mPassengersField;

public Spaceship mSpaceship;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_landing);

    mThrustButton = (Button)findViewById(R.id.thrustButton);
    mTypeLabel = (TextView)findViewById(R.id.typeTextView);
    mPassengersField = (EditText)findViewById(R.id.passengersEditText);

    // Add your code here!
     mSpaceship = new Spaceship("FIREFLY");

}

}

Rock Star!!!