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 Using a Model in the Controller

Gautam Lakum
Gautam Lakum
2,729 Points

error: incompatible types

I am not getting what's the issue. I am a beginner. :(

LandingActivity.java
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;

  public String Spaceship (String text) {
    mSpaceship = text;
  }

    @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!
        Spaceship newSpaceship = new Spaceship("FIREFLY");
    }
}
Spaceship.java
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;
    }
}

2 Answers

Jon Kussmann
PLUS
Jon Kussmann
Courses Plus Student 7,254 Points

In your LandingActivity class, you added a few lines:

 public String Spaceship (String text) {
    mSpaceship = text;
  }

The constructor for the Spaceship class is already taken care of for you in the Spaceship.java file. All you have to do is take mSpaceship (that has already been declared for you) and use the constructor to instantiate it with the type "FIREFLY"

So:

mSpaceship = new Spaceship("FIREFLY");

That should replace the "newSpaceship" line you have.

Hello,

You're getting the incompatible type message most likely because of:

 public String Spaceship (String text) {
    mSpaceship = text;
  }

Here you have a few types being mangled together, like in the assignment mSpaceship = text, you're trying to assign a String into a Spaceship variable, which you cannot do.

By the rest of your code, I'm guessing you're on part 2 where what the task is asking you to do is set the text on the typeTextView to be that of the newly created spaceship's type and to use the spaceship's type getter method to do so. Which to do so, I'd recommend removing the code I mentioned above and starting from that point. If you have any further questions, feel free to ask.