Je reçois une erreur de casting (ne peut pas lancer de chaîne à la station), comment pourrais-je surmonter ce problème, comme je l'aurai besoin que vous utilisez startStation comme paramètre dans d'autres méthodes:Comment surmonter cette exception d'incantation?
Station startStation;
startStation = (Station)(view.getStartStation());
Voici la classe Station
:
public class Station {
// The name of the station.
private String name;
public Station(String name) {
if (name == null) {
throw new NullPointerException(
"The name of a station may not be null");
}
this.name = name;
}
Voici ma méthode getStartStation()
:
public String getStartStation() {
return startStation.getText();
}
S'il vous plaît nous montrer la définition de la classe 'Station'. Et idéalement, la méthode 'getStartStation()' aussi. –
Veuillez lire ce Règlement de Casting http://stackoverflow.com/questions/2233902/java-rules-for-casting – LMK