com.esri.arcgisruntime.ArcGISRuntimeException: Object is already owned.: Already owned

1216
1
Jump to solution
07-27-2022 01:47 AM
MokishLuan
New Contributor

Version : arcgis-android:100.14.0

I have a switch to load satelite map in my app. It was working fine until some android update.

Now it throws an error and crashes the App. It shows ' com.esri.arcgisruntime.ArcGISRuntimeException: Object is already owned.: Already owned.'

I tried clearing the Layers before adding it again. I'm new in this space. kindly go through my code and see if I could do it in a better way.

 

  --------- beginning of crash
2022-07-27 12:34:58.626 19151-19151/com.example.administrator.loccy E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.administrator.loccy, PID: 19151
    com.esri.arcgisruntime.ArcGISRuntimeException: Object is already owned.: Already owned.
        at com.esri.arcgisruntime.internal.jni.CoreFeatureLayer.nativeCreateWithFeatureTable(Native Method)
        at com.esri.arcgisruntime.internal.jni.CoreFeatureLayer.<init>(SourceFile:96)
        at com.esri.arcgisruntime.layers.FeatureLayer.a(SourceFile:4)
        at com.esri.arcgisruntime.layers.FeatureLayer.<init>(SourceFile:21)
        at com.dubaipolice.loccy.activities.MainActivity.setupMap(MainActivity.java:470)
        at com.dubaipolice.loccy.activities.MainActivity.switchMap(MainActivity.java:555)
        at com.dubaipolice.loccy.ResourceTypeDialogFragment$1.onClick(ResourceTypeDialogFragment.java:95)
        at android.view.View.performClick(View.java:7792)
        at android.widget.TextView.performClick(TextView.java:16112)
        at android.widget.CompoundButton.performClick(CompoundButton.java:157)
        at android.view.View.performClickInternal(View.java:7769)
        at android.view.View.access$3800(View.java:910)
        at android.view.View$PerformClick.run(View.java:30213)
        at android.os.Handler.handleCallback(Handler.java:938)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:226)
        at android.os.Looper.loop(Looper.java:313)
        at android.app.ActivityThread.main(ActivityThread.java:8663)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:567)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

 

 

    
final ArcGISMapImageLayer PolyLayer = new ArcGISMapImageLayer("http://XXXXXX");
    ArcGISTiledLayer tiledLayerBaseMap = new ArcGISTiledLayer("http://XXXXXX");

    ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable("http://XXXXXX");
    ServiceFeatureTable resZoneFeatureTable = new ServiceFeatureTable("http://XXXXXX");
    ArcGISMap map = new ArcGISMap();


        public void switchMap() {   //calls on change on switch
        mMapView.getGraphicsOverlays().remove(resGraphicsOverlay);
        mMapView.getGraphicsOverlays().remove(eventGraphicsOverlay);
        map.getOperationalLayers().clear();
        setupMap();
    }


    private void setupMap() {

        if (getBooleanFromSP("satMapON")) {
            Log.i("SAVL","SATMAPON");
            Basemap basemap = new Basemap(PolyLayer);
            map = new ArcGISMap(basemap);
            map.setBasemap(basemap);
            mMapView.getGraphicsOverlays().add(resGraphicsOverlay);
            mMapView.getGraphicsOverlays().add(eventGraphicsOverlay);
            mMapView.setMap(map);
            FeatureLayer featureLayer1 = new FeatureLayer(serviceFeatureTable);
            FeatureLayer resFeatureLayer1 = new FeatureLayer(resZoneFeatureTable);
            SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.rgb(252, 255,  164), 1);
            SimpleRenderer simpleRenderer = new SimpleRenderer(lineSymbol);
            resFeatureLayer1.setRenderer(simpleRenderer);
            map.getOperationalLayers().add(featureLayer1);
            map.getOperationalLayers().add(resFeatureLayer1);
            SimpleLineSymbol lineSymbol2 = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.rgb(0, 0, 255), 2);
            SimpleRenderer simpleRenderer2 = new SimpleRenderer(lineSymbol2);
            featureLayer1.setRenderer(simpleRenderer2);
            MapViewTouchListener mMapViewTouchListener = new MapViewTouchListener(this, mMapView);
            mMapView.setOnTouchListener(mMapViewTouchListener);
        }
        else if (!getBooleanFromSP("satMapON")) {
            Log.i("SAVL","SATMAPOFF");
            Basemap basemap = new Basemap(tiledLayerBaseMap);
            map = new ArcGISMap(basemap);
            map.setBasemap(basemap);
            mMapView.getGraphicsOverlays().add(resGraphicsOverlay);
            mMapView.getGraphicsOverlays().add(eventGraphicsOverlay);
            mMapView.setMap(map);
            FeatureLayer featureLayer2 = new FeatureLayer(serviceFeatureTable);
            FeatureLayer resFeatureLayer2 = new FeatureLayer(resZoneFeatureTable);
            SimpleLineSymbol lineSymbol = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.rgb(252, 255,  164), 1);
            SimpleRenderer simpleRenderer = new SimpleRenderer(lineSymbol);
            resFeatureLayer2.setRenderer(simpleRenderer);
            map.getOperationalLayers().add(featureLayer2);
            map.getOperationalLayers().add(resFeatureLayer2);
            SimpleLineSymbol lineSymbol2 = new SimpleLineSymbol(SimpleLineSymbol.Style.SOLID, Color.rgb(0, 0, 255), 2);
            SimpleRenderer simpleRenderer2 = new SimpleRenderer(lineSymbol2);
            featureLayer2.setRenderer(simpleRenderer2);
            MapViewTouchListener mMapViewTouchListener = new MapViewTouchListener(this, mMapView);
            mMapView.setOnTouchListener(mMapViewTouchListener);
        }

    }

 

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
FPearson
Esri Contributor

Hello @MokishLuan, I believe the problem is that you are re-using the same ServiceFeatureTables to construct different FeatureLayer objects. Try constructing the ServiceFeatureTables inside `setupMap` instead of at the top.

View solution in original post

1 Reply
FPearson
Esri Contributor

Hello @MokishLuan, I believe the problem is that you are re-using the same ServiceFeatureTables to construct different FeatureLayer objects. Try constructing the ServiceFeatureTables inside `setupMap` instead of at the top.