0

为什么

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();

}
4

1 回答 1

0

这里没有足够的代码来给出完整的答案,但是你真的初始化了 coder 吗?如果它在那条线上失败,那么唯一的方法是 coder 是否为空。

于 2012-07-26T16:29:47.140 回答