为什么
getAddress(geoLng,geoLat);
address = coder.getFromLocation(mlat, mLon, 3);
给了我这个例外
07-27 00:21:14.655: E/AndroidRuntime(1228): java.lang.NullPointerException
以下是代码:
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
if (location != null) {
Double geoLat = location.getLatitude();
Double geoLng = location.getLongitude();
String str = ("location:(" + geoLng + "," + geoLat + ")");
getAddress(geoLng,geoLat);
}
}
//
public void getAddress(final double mlat, final double mLon) {
Thread t = new Thread(new Runnable() {
public void run() {
try {
address = coder.getFromLocation(mlat, mLon, 3);
if (address != null || address.size() > 0) {
/*handler.sendMessage(Message.obtain(handler,
Constants.GEOCODER_RESULT));*/
}
}catch (AMapException e) {
// TODO Auto-generated catch block
handler.sendMessage(Message
.obtain(handler, Constants.ERROR));
}}});
t.start();
}
答案 0 :(得分:0)
这里没有足够的代码来提供完整的答案,但你真的初始化了编码器吗?如果它在该行上失败,那么唯一的方法是编码器为空。