Android Build an Interactive Story App The Model-View-Presenter Pattern Adding a Custom Constructor

InvocationTargetException caught

this is my first time getting this type of error, i have no idea how to go about resolving it. please help

Spaceship.java
public class Spaceship {
    public Spaceship spaceShip;
    public String shipType;

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

    public Spaceship(String shipType){           
            shipType = spaceShip.getShipType();      
    }  

    public String getShipType() {
      return shipType;
    }

    public void setShipType(String shipType) {
      this.shipType = shipType;
    }
}

1 Answer

public Spaceship(String shipType){
this.shipType = shipType; 
}

You just have to assign shipType variable to the new String shipType that was passed in the constructor. Use this.shipType to tell compiler that you are talking about original shipType(NOT the one that was passed in constructor) and assign it to the new shipType.

If this.shipType is confusing, you can also do it this way also

public Spaceship(Strings newShipType){
shipType = newShipType; 
}