【问题标题】:ArcGIS for Android LocationService exceptionArcGIS for Android LocationService 异常
【发布时间】:2011-08-24 17:40:50
【问题描述】:

最近我的 Android 项目从 Google Maps 切换到 ESRI ArcGIS,目前我正处于过渡过程中。这只是我从那以后遇到的一个小问题。

每当我启用内置位置服务时,以下代码都会抛出 NullPointerException。而且无论 LocationService.start() 调用是在 try-catch 块中还是在另一个线程中运行都无关紧要:应用程序只会崩溃。

这是Activity 类的sn-p:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map_esri);
    map = (MapView) findViewById(R.id.map);
    map.setExtent(boink);
    map.setOnStatusChangedListener(new OnStatusChangedListener() {
        private static final long serialVersionUID = 1L;
        @Override
        public void onStatusChanged(View source, STATUS status) {
            if(status == STATUS.INITIALIZED) {
                //set up location service
                /*
                 * The following block throws exception and the application crashes.
                 * And it doesn't matter whether I run it from another thread or in a try-catch block!
                 */
                new Handler().post(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            locationService = map.getLocationService();
                            locationService.setLocationListener(MapEsri.this);
//                          locationService.setAccuracyCircleOn(true);
//                          locationService.setBearing(true);
//                          locationService.setAutoPan(true);
                            locationService.start();
                        }
                        catch(Exception e) {
                            e.printStackTrace();
                        }
                    }
                });
            }
        }
    });
}

这是它抛出的异常:

05-13 10:08:55.580: ERROR/AndroidRuntime(28355): java.lang.NullPointerException
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at com.esri.core.geometry.Envelope.<init>(Unknown Source)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at com.esri.core.map.LayerModel.setExtent(Unknown Source)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at com.esri.android.map.LayerView.onSizeChanged(Unknown Source)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at android.view.View.setFrame(View.java:7123)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at android.view.View.layout(View.java:7050)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at com.esri.android.map.MapView.onLayout(Unknown Source)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at android.view.View.layout(View.java:7056)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at android.view.View.layout(View.java:7056)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at android.view.View.layout(View.java:7056)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1049)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1744)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at android.os.Looper.loop(Looper.java:143)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at android.app.ActivityThread.main(ActivityThread.java:5068)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at java.lang.reflect.Method.invokeNative(Native Method)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at java.lang.reflect.Method.invoke(Method.java:521)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-13 10:08:55.580: ERROR/AndroidRuntime(28355):     at dalvik.system.NativeStart.main(Native Method)

我做错了什么?

【问题讨论】:

    标签: android arcgis


    【解决方案1】:

    这可能来得有点晚,但状态可能来自其他来源。 所以地图就是在初始化其他东西时抛出空异常的原因。

     if(source == map && status == STATUS.INITIALIZED) {
                        //set up location service
                        /*
                         * The following block throws exception and the application crashes.
                         * And it doesn't matter whether I run it from another thread or in a try-catch block!
                         */
                        new Handler().post(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    locationService = map.getLocationService();
                                    locationService.setLocationListener(MapEsri.this);
        //                          locationService.setAccuracyCircleOn(true);
        //                          locationService.setBearing(true);
        //                          locationService.setAutoPan(true);
                                    locationService.start();
                                }
                                catch(Exception e) {
                                    e.printStackTrace();
                                }
                            }
                        });
                    }
    

    【讨论】:

    • 您必须为位置制作自己的侦听器您是否为它绑定了任何侦听器? locationService.setLocationListener(MapEsri.this);
    猜你喜欢
    • 1970-01-01
    • 2012-08-30
    • 2019-02-02
    • 2020-03-15
    • 1970-01-01
    • 2014-06-15
    • 2017-02-23
    • 2016-05-12
    • 2021-11-11
    相关资源
    最近更新 更多