Android, java.lang.IllegalArgumentException: No view found for id [..] for fragment [..]

最后都变了- 提交于 2019-12-24 15:06:05

问题


I try to open a dialog in which I have a FrameLayout. While loading a fragment in the Layout I get this exception:

 java.lang.IllegalArgumentException: No view found for id 0x7f080044 (...id/selectionlayout) for fragment ScenesFragment{4166e8a0 #3 id=0x7f080044}

I loaded the Parentlayout correctly and everything else seems correct as well.

AlertDialog.Builder builder = new AlertDialog.Builder(main);
// Get the layout inflater
LayoutInflater inflater = main.getLayoutInflater();
final View v = inflater.inflate(R.layout.selectiondialog, null);
main.getSupportFragmentManager().beginTransaction().replace(R.id.selectionlayout,scenegroups).commit();
builder.setView(v);

selectiondialog.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"
android:padding="10dp" >

<Button
    android:id="@+id/sceneselect_back"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="back" />

<FrameLayout
    android:id="@+id/selectionlayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
</FrameLayout>

</LinearLayout>

Why do I get the exception?

EDIT: It works now.It didn't do the trick, because the FrameLayout was not instanciated. I simply used

main.getSupportFragmentManager().beginTransaction().replace(fl.getId(), scenegroups);

来源:https://stackoverflow.com/questions/20935518/android-java-lang-illegalargumentexception-no-view-found-for-id-for-fragm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!