你好我这里有问题
我有一个用于我的观点数据库的添加和编辑表单,它有两个用于坐标的 EditText,用于经度和纬度,如果我单击该按钮,它有一个获取当前坐标的按钮,两个 EditTexts 填充了坐标和用户可以继续插入或编辑数据
我的代码返回 java.nullPointerException,我不知道为什么...
这是我的代码:
btn_getkoor.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
try{
LocationListener gpsLocation = new MyLocationListener();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, gpsLocation); //new MyLocationListener());
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
final TextView error_text = (TextView) findViewById(R.id.error_text);
if (location != null) {
EditText et_longitude = (EditText) findViewById(R.id.et_longitude);
EditText et_latitude = (EditText) findViewById(R.id.et_latitude);
et_longitude.setText(""+location.getLongitude()); // longitude textview
et_latitude.setText(""+location.getLatitude()); //latitude textview
locationManager.removeUpdates((LocationListener) location);
locationManager = null;
}else{
toastkeun("Terjadi Kesalahan dalam pengambilan koordinat"); //toast function
error_text.setText("Terjadi Kesalahan dalam pengambilan koordinat"); //textview for showing errors
}
}catch(Exception e){
toastkeun(e.toString());
}
}
});
有什么解决办法吗?
我已经设置了清单文件 FYI