ArcGIS for Android LocationService 异常

发布于 2024-11-07 03:50:39 字数 4209 浏览 6 评论 0原文

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

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

这是 Activity 类的片段:

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

我做错了什么?

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
                    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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

Bonjour°[大白 2024-11-14 03:50:39

这可能来得有点晚,但状态可能来自另一个来源。
因此,当初始化其他内容时,映射会抛出 null 异常。

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

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();
                            }
                        }
                    });
                }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文