【发布时间】:2018-12-30 17:17:38
【问题描述】:
我的导航抽屉项目是片段。我想从活动中启动设置片段,但我不断收到以下错误:
java.lang.IllegalArgumentException:未找到片段 SettingsFragment{3f879650 #2 id=0x7f09005a} 的 id 0x7f09005a (example.com.jay:id/content_home) 的视图
我找不到我缺少的东西
我的代码开始片段:
FragmentManager fragmentManager = getSupportFragmentManager();
FragmentTransaction fragmentTransaction=fragmentManager.beginTransaction();
SettingsFragment settings= new SettingsFragment();
fragmentTransaction.add(R.id.content_home , settings);
fragmentTransaction.addToBackStack(null);
fragmentTransaction.commit();
布局文件:activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.jay.HomeActivity"
tools:showIn="@layout/activity_home">
</FrameLayout>
【问题讨论】:
标签: java android android-fragments