I have a little problem with my android app (one Main Activity for the navigation drawer and many fragments).
I havee a list (FragmentList) wich shows me a list of categories. When the user click on a Category he should see the CategoryDetails site. Well,... this is my Error.
java.lang.IllegalArgumentException: No view found for id 0x7f080042 (com.nma:id/container) for fragment CategoryDetailFragment
I'm trying to replace my CategoriesFragment with the CategoryDetailFragment but it do not work... Can anybody help me?;)
My mainActivity.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_height="match_parent"
android:layout_width="match_parent">
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<fragment
android:id="@+id/navigation_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:name="com.nma.NavigationDrawerFragment"/>
</android.support.v4.widget.DrawerLayout>
my click listener from CategoriesFragment.java
@Override
public void onListItemClick(ListView l, View v, int position, long id) {
FragmentManager fm = getFragmentManager();
fm.beginTransaction().replace(R.id.container, new CategoryDetailFragment()).commit();
}
CategoryDetailFragment
public class CategoryDetailFragment extends Fragment {
private View mView;
private Uri mCategoryUri;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mView = inflater.inflate(R.layout.fragment_category_detail, container, false);
return mView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
}
Log
05-19 17:25:25.525 29865-29865/com.nma E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.IllegalArgumentException: No view found for id 0x7f080042 (com.nma:id/container) for fragment CategoryDetailFragment{425649e0 #0 id=0x7f080042} at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:930) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115) at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682) at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478) at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:446) at android.os.Handler.handleCallback(Handler.java:730) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:213) at android.app.ActivityThread.main(ActivityThread.java:5225) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:741) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) at dalvik.system.NativeStart.main(Native Method)
Activity
are you subclassing?ActionBarActivity
?FragmentActivity
? What I mean is are you sure you are using the correctFragmentManager
? And also as I understand it you have something like this:Activity -> Fragment1
and want theFragment1
to be replaced? I'm asking because if you have something likeActivity -> Fragment1 -> Fragment2
and you wanted to replaceFragment2
you would have to use theChildFragmentManager
. – Xaver Kapeller