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

Stuck on Challenge Task 2 on the Custom Constructors code challenge. Everything I try doesn't work:

I've tried the following;

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

Not sure what I'm missing any help would be appreciated and yes I'm a newb :(.

5 Answers

It does look right. I just did the challenge again and it worked. Here is the code that pass to compare.

public class Spaceship {
    public String mType;

    public String getType() {
      return mType;
    }

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

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

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

Are you still including the first constructor with no parameters that sets mType to "SHUTTLE"? Your second constructor looks right so make sure you have both constructors included.

Yep. I have that on there as well. Not sure what I'm missing, this is getting frustrating. Thank you for your help. I'll keep at it, hopefully something will stick.

I am getting the same error

Thanks that worked. I missed something, I re-started the challenge and it worked. I guess I had a typo I wasn't catching. Much appreciated, thanks for everyones contribution.