Java 未找到id为0x7f040005的Android片段视图

Java 未找到id为0x7f040005的Android片段视图,java,android,android-fragments,android-studio,Java,Android,Android Fragments,Android Studio,这是我的片段类。我需要从一个片段移动到另一个片段。单击处理程序之后,我需要用另一个片段替换现有片段 fragment\u forum.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

这是我的片段类。我需要从一个片段移动到另一个片段。单击处理程序之后,我需要用另一个片段替换现有片段

fragment\u forum.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_weight="1"
    android:layout_height="match_parent" >

    <ExpandableListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/forumListView"
        android:clickable="true"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_margin="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="10dp" />

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

    <EditText
        android:id="@+id/txtTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="Title"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textMultiLine"
        android:ems="10"
        android:id="@+id/txtDescription" />


</LinearLayout>
fragment\u new\u post.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_weight="1"
    android:layout_height="match_parent" >

    <ExpandableListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/forumListView"
        android:clickable="true"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_margin="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginBottom="10dp" />

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

    <EditText
        android:id="@+id/txtTitle"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:hint="Title"/>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:inputType="textMultiLine"
        android:ems="10"
        android:id="@+id/txtDescription" />


</LinearLayout>
当我在我的设备上运行这个时,我得到了一个错误

java.lang.IllegalArgumentException: No view found for id 0x7f040005
应用程序已经重新启动。
请帮助我。

您不能使用
事务。替换(R.layout.fragment\u论坛,fragment)
替换
Fragment
,因为
R.layout.Fragment\u forum
是布局id,而不是
containerWebID
。因此,您需要一个容器来容纳不同的
片段,容器可以是:

<FrameLayout 
  android:id="@+id/fragment_container"
  android:layout_width="match_parent"
  android:layout_height="wrap_content" />

然后可以使用
transaction.add/replace(R.id.fragment\u container,newfragment)


希望这有帮助

哪一行导致该异常?如果无法访问资源,请清理项目。错误与事务一起。替换(R.layout.fragment\u forum,fragment)我清理并重建了项目。。但它仍然显示出同样的效果error@pbabcdefp事务出错。替换(R.layout.fragment\u论坛,fragment)