执行"的getAddress(geoLng,geoLat);"空指针异常 [英] execute the "getAddress(geoLng,geoLat);" NullPointerException

查看:234
本文介绍了执行"的getAddress(geoLng,geoLat);"空指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么

 的getAddress(geoLng,geoLat);
地址= coder.getFromLocation(多点定位,mLon,3);
 

给我这个异常

  07-27 00:21:14.655:E / AndroidRuntime(1228):显示java.lang.NullPointerException
 

下面是code:

  @覆盖
公共无效onLocationChanged(位置定位){
    // TODO自动生成方法存根
    如果(位置!= NULL){
        双geoLat = location.getLatitude();
        双geoLng = location.getLongitude();
        字符串str =(位置:(+ geoLng +,+ geoLat +));


        的getAddress(geoLng,geoLat);

    }
}
//
公共无效的getAddress(决赛双多点定位,最终双mLon){
    线程t =新主题(新的Runnable(){
        公共无效的run(){
            尝试 {

                地址= coder.getFromLocation(多点定位,mLon,3);
                如果(!地址=空|| address.size()大于0){

                    /*handler.sendMessage(Message.obtain(handler,
                            Constants.GEO codeR_RESULT)); * /

                }

        }赶上(AMapException E){
            // TODO自动生成的catch块
            handler.sendMessage(消息
                    .obtain(处理器,Constants.ERROR));

    }}});

    t.start();

}
 

解决方案

没有足够的code在这里给一个完整的答案,但你实际上初始化codeR?如果没有在该行,那么唯一的办法是,如果codeR为null。

why does

getAddress(geoLng,geoLat);
address = coder.getFromLocation(mlat, mLon, 3);

gives me this exception

07-27 00:21:14.655: E/AndroidRuntime(1228): java.lang.NullPointerException

Below is the code:

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

}

解决方案

There is not enough code here to give a full answer, but did you actually initialize coder? If it is failing on that line, then the only way is if coder was null.

这篇关于执行"的getAddress(geoLng,geoLat);"空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆