首页 / 浏览问题 / 移动GIS / 问题详情
imobile 释放资源程序崩溃
76EXP 2021年09月08日
各位大佬,我在点击返回按钮关闭页面释放资源时,程序崩溃,释放资源的代码如下:

  if (mMapControl!!.map != null) {
                mMapControl!!.map.close()//从MapControl中获取的map对象仅需要关闭即可,无需dispose
            }
            if (mMapControl != null) mMapControl!!.dispose()
            mMapControl=null;
            if (mWorkspace != null) {//  mWorkspace!!.close();和 mWorkspace!!.dispose()第二次打开页面时,程序会崩溃(关闭页面等待几秒即可重新打开)
                mWorkspace!!.close();
                mWorkspace!!.dispose()
                mWorkspace=null;

            }

崩溃信息:

E/: [qarth_debug:]  get PatchStore::createDisableExceptionQarthFile method fail.
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.xtkj.test PID: 14017
    java.lang.IllegalStateException: getMap()
    
        at com.supermap.mapping.MapControl2.getMap(MapControl2.java:1227)
        at com.supermap.mapping.MapControl.getMap(MapControl.java:496)
        at com.supermap.mapping.MapView.b(MapView.java:398)
        at com.supermap.mapping.MapView.a(MapView.java:189)
        at com.supermap.mapping.MapView.onLayout(MapView.java:170)
        at android.view.View.layout(View.java:20948)
        at android.view.ViewGroup.layout(ViewGroup.java:6279)
        at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
        at android.view.View.layout(View.java:20948)
        at android.view.ViewGroup.layout(ViewGroup.java:6279)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1842)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1686)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1595)
        at android.view.View.layout(View.java:20948)
        at android.view.ViewGroup.layout(ViewGroup.java:6279)
        at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1083)
        at android.view.View.layout(View.java:20948)
        at android.view.ViewGroup.layout(ViewGroup.java:6279)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at android.view.View.layout(View.java:20948)
        at android.view.ViewGroup.layout(ViewGroup.java:6279)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1842)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1686)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1595)
        at android.view.View.layout(View.java:20948)
        at android.view.ViewGroup.layout(ViewGroup.java:6279)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at android.view.View.layout(View.java:20948)
        at android.view.ViewGroup.layout(ViewGroup.java:6279)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1842)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1686)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1595)
        at android.view.View.layout(View.java:20948)
        at android.view.ViewGroup.layout(ViewGroup.java:6279)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:325)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:261)
        at com.android.internal.policy.DecorView.onLayout(DecorView.java:9
I/System.out: 崩溃:getMap()

请问我该如何解决这个问题?

另外,我试着在释放资源的时候不释放mapcontroll,程序不会崩溃,但是如果在释放资源的时候释放了工作空间的资源,关闭页面,在打开地图页面(间隔时间很短),程序也会崩溃。

1个回答

您好,看崩溃信息是获取地图时崩溃的,您那边调试一下代码是哪句代码崩溃发生的崩溃呢?使用iMobile for Android是哪个版本
9,147EXP 2021年09月08日
if (mMapControl != null) mMapControl!!.dispose()

  if (mWorkspace != null) {//  mWorkspace!!.close();和 mWorkspace!!.dispose()第二次打开页面时,程序会崩溃(关闭页面等待几秒即可重新打开)
                mWorkspace!!.close();
                mWorkspace!!.dispose()
                mWorkspace=null;

            }

释放mapcontroll和释放workspace都会导致程序崩溃,目前经过自我排查,发现mapcontroll释放导致的程序崩溃,是因为在此之前未将地图中的标注移除,在mapcontroll.dispose()之前添加mMapView.removeAllCallOut();程序崩溃情况转好,但是加上workspace.dispose()或者workspace.close(),页面关闭不会崩溃,但是再次打开地图时,又出现崩溃的情况,这种问题,目前还不清楚是什么造成的。
再次打开地图时相关变量是否都重新初始化了呢?麻烦发下崩溃日志
...