我有以下设置
public class MainActivity extends AppCompatActivity implements LocationListener {
GeoPoint pointTarget;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
pointTarget.setLatitude(51.4245);
pointTarget.setLongitude(3.1455);
}
}
将Attempt to invoke virtual method 'void org.osmdroid.util.GeoPoint.setLatitude(double)' on a null object reference
抛向pointTarget.setLatitude(51.4245);
这两个实参都是双精度,所以这不是问题。pointTarget
也已经实例化。谁能告诉我出了什么事?
感谢您参考什么是NullPointerException,以及我如何修复它?我现在已经实例化为private GeoPoint pointTarget = new GeoPoint(0.0,0.0);
,它解决了这个问题。也许我应该切换到Kotlin,它显然没有nullpointerexception。