当碎片第二次打开时,应用程序关闭力量

时间:2015-02-02 12:39:54

标签: android android-layout android-fragments

我从xml文件创建一个片段,并直接在activity中的setcontentview方法中添加xml文件。如果我重新打开那个片段导致力量关闭,它第一次工作正常。

错误日志中的问题是

02-02 18:09:22.323: E/AndroidRuntime(5591): FATAL EXCEPTION: main
02-02 18:09:22.323: E/AndroidRuntime(5591): Process: com.pal.newloginscreenui, PID: 5591
02-02 18:09:22.323: E/AndroidRuntime(5591): android.view.InflateException: Binary XML file line #7: Error inflating class fragment
02-02 18:09:22.323: E/AndroidRuntime(5591):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at com.pal.newloginscreenui.DashboardActivity.display_popopMenu(DashboardActivity.java:112)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at com.pal.newloginscreenui.DashboardActivity.onClick(DashboardActivity.java:80)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at android.view.View.performClick(View.java:4463)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at android.view.View$PerformClick.run(View.java:18770)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at android.os.Handler.handleCallback(Handler.java:808)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at android.os.Handler.dispatchMessage(Handler.java:103)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at android.os.Looper.loop(Looper.java:193)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at android.app.ActivityThread.main(ActivityThread.java:5292)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at java.lang.reflect.Method.invokeNative(Native Method)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at java.lang.reflect.Method.invoke(Method.java:515)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:824)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:640)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at dalvik.system.NativeStart.main(Native Method)
02-02 18:09:22.323: E/AndroidRuntime(5591): Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Duplicate id 0x7f06004b, tag null, or parent id 0xffffffff with another fragment for com.pal.newloginscreenui.NavigationMenuFragment
02-02 18:09:22.323: E/AndroidRuntime(5591):     at android.app.Activity.onCreateView(Activity.java:4824)
02-02 18:09:22.323: E/AndroidRuntime(5591):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
02-02 18:09:22.323: E/AndroidRuntime(5591):     ... 17 more

xml:

<FrameLayout android:id="@+id/containner"
   android:layout_width="match_parent" android:layout_height="match_parent">
<fragment android:id="@+id/frag"
   android:name="com.pal.newloginscreenui.NavigationMenuFragment" 
   android:layout_width="match_parent"
   android:layout_height="match_parent"/> 
</FrameLayout>

我正在打电话的Popupwindow

DoctorGlobal.pw = new PopupWindow(DashboardActivity.this);// create a popup window
    DoctorGlobal.pw.setTouchable(true);
    DoctorGlobal.pw.setFocusable(true);
    DoctorGlobal.pw.setOutsideTouchable(true);
    DoctorGlobal.pw.setTouchInterceptor(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {

            if (event.getAction() == MotionEvent.ACTION_OUTSIDE) { 
                DoctorGlobal.pw.dismiss();
                return true;
            }
            return false;
        }
    });

    int popWndwidth = (int)(width/4)*3;
    DoctorGlobal.pw
            .setWidth(popWndwidth);
    DoctorGlobal.pw
            .setHeight(android.view.ViewGroup.LayoutParams.MATCH_PARENT);
    View contentView = getLayoutInflater().inflate(R.layout.navg_menu, null);
    DoctorGlobal.pw.setContentView(contentView);
    container = (FrameLayout) contentView.findViewById(R.id.containner);
    DoctorGlobal.pw.showAsDropDown(v, 0, 0);
具有上述xml代码的navg_menu中的

1 个答案:

答案 0 :(得分:0)

您的错误:

android.view.InflateException: Binary XML file line #7: Error inflating class fragment

  ....

Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: 
Duplicate id 0x7f06004b, tag null, or parent id 0xffffffff with another 
fragment for com.pal.newloginscreenui.NavigationMenuFragment

你的xml标签:

<FrameLayout android:id="@+id/containner"
  ....                                      >
<fragment android:id="@+id/frag"
    android:name="com.pal.newloginscreenui.NavigationMenuFragment" 
  ....

你的java:

View contentView = getLayoutInflater().inflate(R.layout.navg_menu, null);

您有getLayoutInflater().inflate(R.layout.navg_menu, null);

看起来navg_menu id不存在,或者它是你试图膨胀的菜单xml,也许应该用于菜单并确保你有一个正确的id来创建你的contentView。 ;

`MenuInflater inflater = getMenuInflater();`

`getMenuInflater().inflate`

或者您正在访问重复的ID。 希望这可以帮助您调试它。

我认为这里的答案可以帮助你:
https://stackoverflow.com/a/8513735/3956566

完成后,

或解除片段,如下所示:

https://stackoverflow.com/a/14966061/3956566