Class MyApplication is created :
public class MyApplication extends Application { // code - freeCodeCamp.org
private static MyApplication singleton;
private List<Location> myLocations;
public List<Location> getMyLocations() {
return myLocations;
}
public void setMyLocations(List<Location> myLocations) {
this.myLocations = myLocations;
}
public MyApplication getInstance(){
return singleton;
}
public void OnCreate() {
super.onCreate();
singleton = this;
myLocations = new ArrayList<>();
}
}
MyApplication myApplication = (MyApplication)getApplicationContext();
savedLocations = myApplication.getMyLocations();
savedLocations.add(currentLocation);
currentLocation具有有效的位置值。有什么提示吗?谢谢
MyLocations
为null,因为您拼错了onCreate
方法签名,而且实际上从未调用过它。
您应该更改以下内容:
public void OnCreate() {
对此:
@Override
public void onCreate() {