java.lang.IllegalArgumentException:找不到片段DiscDispFragment的ID 0x184f(未知)的视图

安格斯:

DiscFragment.java:(更新

public class DiscFragment extends DagFragment {
//    @BindView(R.id.dispFrag)
//    LinearLayout discDispLayout;

@BindView(R.id.get_button)
Button getButton;

@NonNull
@Override
public String getFragmentTitle(@NonNull Context context) {
    return context.getString(R.string.ex_disp);
}

@OnClick(R.id.getbutton)
void onGetClicked() {
    DiscDispFragment fragment = new DiscDispFragment();
    FragmentManager fmt = getChildFragmentManager();
    if (fmt != null) {
        FragmentTransaction fragmentTransaction = fmt.beginTransaction();
        fragmentTransaction.replace(R.id.discover, fragment);
        fragmentTransaction.commit();
    }
}

@Override
protected int getFragmentLayout() {
    return R.layout.get_started;
}

}

DiscDispFragment.java:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(getFragmentLayout(), container, false);
    ButterKnife.bind(this, rootView);
    return rootView;
}
@Override
    protected int getFragmentLayout() {
        return R.layout.dispFragment;
    }

dispFragment.xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="?attr/background_color"
    android:layoutDirection="locale"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/dispFrag"
        android:layout_width="match_parent"
        android:layout_height="750dp"
        android:layout_gravity="center"
        android:orientation="vertical">

        <ImageView
            android:id="@+id/cancel_button"
            android:layout_width="@dimen/progress_bar_small"
            android:layout_height="@dimen/progress_bar_small"
            android:background="?attr/bg_color"
            android:clickable="true"
            android:contentDescription="@string/st_away"
            android:scaleType="center"
            android:tint="@color/white"
            android:visibility="visible"
            app:srcCompat="@drawable/st_close" />

        <TextView
            android:id="@+id/st_to"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="17dp"
            android:layout_marginBottom="151dp"
            android:background="@drawable/bottom_sheet_background"
            android:text="@string/st_to"
            android:textAlignment="center"
            android:textColor="@color/gray_color"
            android:textSize="@dimen/pad_12"
            android:textStyle="bold" />

        <ProgressBar
            android:id="@+id/progress"
            style="?android:attr/progressBarStyleSmall"
            android:layout_width="@dimen/progress_bar"
            android:layout_height="@dimen/progress_bar"
            android:layout_gravity="center"
            android:layout_marginTop="@dimen/element_margin"
            android:indeterminate="true"
            android:progressBackgroundTint="#606067"
            android:progressTint="#8e8e93" />

        <TextView
            android:id="@+id/disp_state_message"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="@dimen/element_margin"
            android:gravity="center"
            android:paddingStart="@dimen/element_margin"
            android:paddingEnd="@dimen/element_margin"
            android:text="@string/progress_message"
            android:textColor="@color/black_color"
            android:textSize="@dimen/st_size" />

        <androidx.appcompat.widget.AppCompatButton
            android:id="@+id/btn_error_action"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="@dimen/element_margin"
            android:background="@color/butn_background"
            android:padding="@dimen/butn_padding"
            android:textColor="@color/white"
            tools:text="@string/hello" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/discays"
            android:layout_width="match_parent"
            android:layout_height="145dp"
            tools:listitem="@layout/item_discovered_display_item" />
    </LinearLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

get_started.xml :(已更新

<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/round_corners">

    <LinearLayout
        android:id="@+id/des_get_started"
        android:layout_width="match_parent"
        android:layout_height="675dp"
        android:layout_gravity="center"
        android:layout_marginBottom="51dp"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="51dp" />

        <ImageView
            android:id="@+id/sheet_image"
            android:layout_width="232dp"
            android:layout_height="177dp"
            android:layout_gravity="center"
            android:layout_marginTop="51dp"
            android:layout_marginBottom="32dp"
            android:contentDescription="@string/disp_name"
            android:padding="16dp"
            android:src="@drawable/im"
            android:textAlignment="center" />

        <TextView
            android:id="@+id/sheet_title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="8dp"
            android:padding="16dp"
            android:text="@string/st_away"
            android:textAlignment="center"
            android:textColor="@color/darktheme"
            android:textSize="@dimen/s21"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/sheet_desc"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="24dp"
            android:padding="16dp"
            android:text="@string/st_desc"
            android:textAlignment="center"
            android:textColor="@color/black_darktheme"
            android:textSize="@dimen/s_21" />

        <Button
            android:id="@+id/get_started_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:background="@drawable/get_started_background"
            android:padding="16dp"
            android:text="@string/get_started_button"
            android:textAlignment="center"
            android:textColor="@color/white"
            android:textSize="@dimen/size_15dp" />

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

</androidx.coordinatorlayout.widget.CoordinatorLayout>

例外情况:

2020-09-23 20:00:23.509 4897-4897/com.misc.dd E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.misc.dd, PID: 4897
    java.lang.IllegalArgumentException: No view found for id 0x184f (unknown) for fragment DiscDispFragment{58583d9} (17f05957-c8f3-4a58-9405-0f7ef88f401d) id=0x184f}
        at androidx.fragment.app.FragmentStateManager.createView(FragmentStateManager.java:315)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1187)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)
        at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)
        at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)
        at androidx.fragment.app.BackStackRecord.executeOps(BackStackRecord.java:447)
        at androidx.fragment.app.FragmentManager.executeOps(FragmentManager.java:2169)
        at androidx.fragment.app.FragmentManager.executeOpsTogether(FragmentManager.java:1992)
        at androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute(FragmentManager.java:1947)
        at androidx.fragment.app.FragmentManager.execPendingActions(FragmentManager.java:1849)
        at androidx.fragment.app.FragmentManager$4.run(FragmentManager.java:413)
        at android.os.Handler.handleCallback(Handler.java:789)
        at android.os.Handler.dispatchMessage(Handler.java:98)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6938)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
ianhanniballake:

当您写:

DiscDispFragment fragment = new DiscDispFragment();
FragmentManager fmt = getChildFragmentManager();
FragmentTransaction fragmentTransaction = fmt.beginTransaction();
fragmentTransaction.replace(R.id.dispFrag, fragment);

您的意思是您想要:

  1. 创建一个新DiscDispFragment实例
  2. 使用这种getChildFragmentManager()方法,您希望新片段完全包含在父片段的视图中-在这种情况下,您DiscFragmentgetting_started布局
  3. R.id.dispFragnew 替换容器中任何现有的Fragment DiscDispFragment,将DiscDispFragment的布局添加到该容器中。

你得到一个错误的原因是,R.id.dispFrag不是一个FrameLayoutViewGroup你内DiscFragment的布局。

为了解决这个问题,您有两种选择:

  • 如果您确实希望将DiscDispFragment的子片段作为DiscFragment,则需要在布局中添加FrameLayoutFragmentContainerView,这就是您DiscDispFragment要添加到的布局
  • 如果你不想DiscDispFragment成为一个孩子片段,那么你需要使用getChildFragmentManager()requireActivity().getSupportFragmentManager()将是活动的FragmentManager(您将在“活动”的布局中使用容器ID的位置),或者将使用getParentFragmentManager()/ getFragmentManager()(取决于您使用的Fragments的版本)来访问FragmentManager添加DiscFragment到其中的内容(在使用您最初添加DiscFragment到的任何容器ID )。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

java.lang.IllegalArgumentException:找不到片段NewLogFragment的ID的视图

java.lang.IllegalArgumentException:找不到片段的ID 0x1020002(android:id / content)的视图

片段:java.lang.IllegalArgumentException:找不到ID为0x7f0c006f的视图

java.lang.IllegalArgumentException:找不到片段FmMenu的ID 0x7f090047(“项目名称”:id /内容)的视图

java.lang.IllegalArgumentException:找不到ID为0x7f0c0098的视图

java.lang.IllegalArgumentException:找不到ID为0x7f0901d1的视图

由WindowManager添加的视图上的ViewPager获取“ java.lang.IllegalArgumentException:找不到ID的视图”

java.lang.IllegalArgumentException:未找到片段 HomeFragment 的 id 0x7f0e0084 (com.example.dell.foodcourt:id/content) 的视图

java.lang.IllegalArgumentException: 没有找到 id 0x7f0d006d 的视图

IllegalArgumentException:尝试 setView 时找不到片段 id 的视图

Proguard-java.lang.IllegalArgumentException:找不到通用的超类

java.lang.IllegalArgumentException:使用未知视图调用 sideInput()

java.lang.IllegalArgumentException:未知实体

VolleyError:java.lang.IllegalArgumentException:超时<0

IllegalArgumentException:从另一个片段和onResume调用返回时,找不到id的视图

Proguard-找不到apache cxf / java.lang.IllegalArgumentException的常见超类异常

找不到java.lang.ArrayIndexOutOfBoundsException的问题

java.lang.ClassNotFoundException:找不到实现

java.lang.NullPointerException找不到源

IllegalArgumentException:找不到ID为0x7f07004e android的视图

片段中的Android数据绑定-IllegalArgumentException:找不到视图

java.lang.IllegalArgumentException:未知参数名称:客户

引起原因:java.lang.IllegalArgumentException:未知的保留键'_typeConverter'

片段交易-找不到ID为0x7f090022的视图

Android片段找不到ID的视图?

Android PreferenceFragment找不到片段ID的视图

找不到片段GameActivityFragment的ID的视图

Android:自定义 AlertDialog,viewPager:java.lang.IllegalArgumentException:未找到 id 的视图

ViewPager作为listview行java.lang.IllegalArgumentException:未找到ID的视图