美文网首页FlutterAndroid技术分享
java.lang.IllegalStateException:

java.lang.IllegalStateException:

作者: Air_w | 来源:发表于2020-07-21 16:42 被阅读0次

    java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

    
    W/System.err(31384): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
    W/System.err(31384):    at android.view.ViewGroup.addViewInner(ViewGroup.java:5207)
    W/System.err(31384):    at android.view.ViewGroup.addView(ViewGroup.java:5028)
    W/System.err(31384):    at android.view.ViewGroup.addView(ViewGroup.java:5000)
    W/System.err(31384):    at com.amap.api.maps.MapView.onCreate(MapView.java:135)
    W/System.err(31384):    at com.air.main.ai_amap.location.MapLocationPlatformView.getView(MapLocationPlatformView.kt:90)
    W/System.err(31384):    at io.flutter.plugin.platform.VirtualDisplayController.getView(VirtualDisplayController.java:209)
    W/System.err(31384):    at io.flutter.plugin.platform.PlatformViewsController$1.createPlatformView(PlatformViewsController.java:143)
    W/System.err(31384):    at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:95)
    W/System.err(31384):    at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:59)
    W/System.err(31384):    at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:230)
    W/System.err(31384):    at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:85)
    W/System.err(31384):    at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:664)
    W/System.err(31384):    at android.os.MessageQueue.nativePollOnce(Native Method)
    W/System.err(31384):    at android.os.MessageQueue.next(MessageQueue.java:341)
    W/System.err(31384):    at android.os.Looper.loop(Looper.java:184)
    W/System.err(31384):    at android.app.ActivityThread.main(ActivityThread.java:7922)
    W/System.err(31384):    at java.lang.reflect.Method.invoke(Native Method)
    W/System.err(31384):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    W/System.err(31384):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:982)
    
    

    解决办法:
    • 解决前状态如下:
    
        /** Init */
        init {
            //Method call handler
            methodChannel.setMethodCallHandler(this);
        }
    
        /** Platform view */
        override fun getView(): View {
            mMapView.let {
                mMapView.onCreate(null);
                mMapView.onResume();
                mMapView.map.uiSettings.apply {
                    isCompassEnabled = true;
                }
                mMapView.map.setOnMarkerClickListener(this)
                mInfoWindowAdapter.setOnConfirmListener(this);
                mMapView.map.setInfoWindowAdapter(mInfoWindowAdapter);
            }
            return mMapView;
        }
    
    
    

    • 解决后状态如下:
    
        /** Init */
        init {
            //Method call handler
            methodChannel.setMethodCallHandler(this);
            
            mMapView.let {
                mMapView.onCreate(null);
                mMapView.onResume();
                mMapView.map.uiSettings.apply {
                    isCompassEnabled = true;
                }
                mMapView.map.setOnMarkerClickListener(this)
                mInfoWindowAdapter.setOnConfirmListener(this);
                mMapView.map.setInfoWindowAdapter(mInfoWindowAdapter);
            }
        }
    
        /** Platform view */
        override fun getView(): View {
            return mMapView;
        }
    
    
    

    相关文章

      网友评论

        本文标题:java.lang.IllegalStateException:

        本文链接:https://www.haomeiwen.com/subject/eyzikktx.html