Android Build an Interactive Story App The Model-View-Presenter Pattern Creating a Data Model

Luke Horvath
Luke Horvath
590 Points

can not return string as int

compiler error;

can not return String as Int

Spaceship.java
public class Spaceship{

  public String shipType;

  public int getShipType(){
    return "shipType";
  }
};

2 Answers

Jason Wiram
seal-mask
.a{fill-rule:evenodd;}techdegree
Jason Wiram
Full Stack JavaScript Techdegree Student 41,827 Points

There are two things you need to fix here.

  1. Your "getter" method should return the value of the shipType variable. That variable is of type String. That means your method must return a String. Notice the "public String" that tells the method what kind of value to expect. Your method was returning a String but expecting an int. The correct version here:
public String getShipType() {
    return "shipType";
  }
  1. Second your return statement is returning a hard-coded String "shipType." It should be returning the value of the shipType variable as follows. This is done by using the variable name (no quotation marks).
public String getShipType() {
    return shipType;
  }

Hello. You declared shipType as String and you want it as int. In this case return type must be same as type of variable.