1

我正在尝试将片段添加到对话框片段的 xml 布局中,但它不起作用,当我尝试打开对话框片段时,应用程序崩溃,因为片段包含在布局中

下面是xml布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

 <fragment
         android:id="@+id/flContent"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:padding = "10dp"
         class="com.OptimusApps.stayhealthy.AndroidXMLParsingActivity" />

</LinearLayout>

这是我的日志猫

08-17 19:59:02.316: E/AndroidRuntime(5222): FATAL EXCEPTION: main
08-17 19:59:02.316: E/AndroidRuntime(5222): android.view.InflateException: Binary XML file line #7: Error inflating class fragment
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at com.OptimusApps.stayhealthy.BodyDialogue.onCreateView(BodyDialogue.java:64)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.support.v4.app.Fragment.performCreateView(Fragment.java:1470)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:925)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:299)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at com.OptimusApps.stayhealthy.BodyDialogue.onCreateView(BodyDialogue.java:64)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at     android.support.v4.app.Fragment.performCreateView(Fragment.java:1470)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:925)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1102)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1458)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:438)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.os.Handler.handleCallback(Handler.java:605)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.os.Looper.loop(Looper.java:137)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.app.ActivityThread.main(ActivityThread.java:4575)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at java.lang.reflect.Method.invokeNative(Native Method)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at java.lang.reflect.Method.invoke(Method.java:511)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at dalvik.system.NativeStart.main(Native Method)

以下是它的原因,我不知道如何解决

08-17 19:59:02.316: E/AndroidRuntime(5222): Caused by: java.lang.IllegalArgumentException: Binary XML file line #7: Duplicate id 0x7f0a0031, tag null, or parent id 0x0 with another fragment for com.OptimusApps.stayhealthy.AndroidXMLParsingActivity
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:285)
08-17 19:59:02.316: E/AndroidRuntime(5222):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
08-17 19:59:02.316: E/AndroidRuntime(5222):     ... 30 more
4

1 回答 1

0

看起来您的应用中还有另一个名为 flContent 的 id,请尝试更改 id 名称。

于 2013-08-18T02:27:42.910 回答