开发者

ArcGIS for Android LocationService exception

Recently my Android project was switched from Google Maps to ESRI ArcGIS and currently I'm in the process of transition. Here's just one little issue I've faced since.

The following code throws NullPointerException whenever I enable the built-in location service. And it doesn't even matter whether the LocationService.start() call is in a try-catch block or runs in another thread: the application just crashes.

Here's a snippet of the Activity class:

@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
                  开发者_Go百科  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();
                        }
                    }
                });
            }
        }
    });
}

This is the exception it throws:

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)

What do I do wrong?


This may have come a little late but the status may be coming from another source. So the map is what is throwing the null exception when something else is initialized.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜