use*_*183 0 java casting object
我收到一个强制转换错误(无法从字符串转换为工作站),我怎么能克服这个问题,因为我需要在其他方法中使用startStation作为参数:
Station startStation;
startStation = (Station)(view.getStartStation());
Run Code Online (Sandbox Code Playgroud)
这是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;
}
Run Code Online (Sandbox Code Playgroud)
这是我的getStartStation()方法:
public String getStartStation() {
return startStation.getText();
}
Run Code Online (Sandbox Code Playgroud)
只需Station使用现有的构造函数创建一个对象:
Station startStation = new Station(view.getStartStation());
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
65 次 |
| 最近记录: |