实习杂记(22)being added, but it already has a parent

06-12 11:39:14.088: E/AndroidRuntime(22713): FATAL EXCEPTION: main
06-12 11:39:14.088: E/AndroidRuntime(22713): Process: com.wust.wpsmyvideoview, PID: 22713
06-12 11:39:14.088: E/AndroidRuntime(22713): java.lang.RuntimeException: view android.widget.FrameLayout{23eba7a6 V.E..... ......I. 0,0-0,0 #7f070001 app:id/mediacontroller_framelayout} being added, but it already has a parent
06-12 11:39:14.088: E/AndroidRuntime(22713): at android.view.View.assignParent(View.java:13014)
06-12 11:39:14.088: E/AndroidRuntime(22713): at android.view.ViewRootImpl.setView(ViewRootImpl.java:645)
06-12 11:39:14.088: E/AndroidRuntime(22713): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:272)
06-12 11:39:14.088: E/AndroidRuntime(22713): at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:69)
06-12 11:39:14.088: E/AndroidRuntime(22713): at com.wust.view.CopyMyMediaController.show(CopyMyMediaController.java:277)
06-12 11:39:14.088: E/AndroidRuntime(22713): at com.wust.view.CopyMyMediaController.show(CopyMyMediaController.java:235)
06-12 11:39:14.088: E/AndroidRuntime(22713): at com.wust.view.MyVideoView$2.onPrepared(MyVideoView.java:345)
06-12 11:39:14.088: E/AndroidRuntime(22713): at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:2812)
06-12 11:39:14.088: E/AndroidRuntime(22713): at android.os.Handler.dispatchMessage(Handler.java:102)
06-12 11:39:14.088: E/AndroidRuntime(22713): at android.os.Looper.loop(Looper.java:155)
06-12 11:39:14.088: E/AndroidRuntime(22713): at android.app.ActivityThread.main(ActivityThread.java:5721)
06-12 11:39:14.088: E/AndroidRuntime(22713): at java.lang.reflect.Method.invoke(Native Method)
06-12 11:39:14.088: E/AndroidRuntime(22713): at java.lang.reflect.Method.invoke(Method.java:372)
06-12 11:39:14.088: E/AndroidRuntime(22713): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)

06-12 11:39:14.088: E/AndroidRuntime(22713): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)



这个问题最好的解决办法是:根据view找到父ViewGroup,全部删掉


            ViewGroup vg =  (ViewGroup) mRoot.getParent();
            if(vg!=null){
            vg.removeAllViews();
            }      
    
            mWindowManager.addView(mRoot, lp);

红色的代码是添加的

你可能感兴趣的:(实习,实习)