java.lang.IllegalArgumentException: No view found for id 0x7f090047 (“project name”:id/content) for fragment FmMenu

冷暖自知 提交于 2019-11-28 00:14:58

I think I have found something.

fragmentManager.beginTransaction()
                .replace(R.id.linear, fragment).commit();

As you see you try to replace the layout R.id.linear with your fragment. But the R.id.linear is the RelativeLayout you use in your fragment_menu.xml. You should replace the layout in your activity_menu.xml with the current fragment. So I would suggest:

fragmentManager.beginTransaction().replace(R.id.container, fragment).commit();

And in your activity_menu.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ff0a393d">

    <!-- Linearlayout to display Fragments -->
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:id="@+id/container">

EDIT:

For the new error: There is a problem with your memory. This often happens when ImageViews are filled by big ressources. So there is only one position where you use an ImageView:

 @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View rootView = inflater.inflate(R.layout.fragment_menu, container, false);

            ImageView imagenView = (ImageView) rootView.findViewById(R.id.imageView1);
            imagenView.setImageResource(imagen);
            return rootView;
        }

As you see, your imagenView is filled by the resource imagen

imagenView.setImageResource(imagen);

Probably you get the OutOfMemoryError there. As a solution, try this:

try {
    imagenView.setImageResource(imagen);
} catch (OutOfMemoryError e) {
    //fill your ImageView with something smaller .. maybe a smaller resolution
    Log.e("PlaceholderFragment", "Error: OutOfMemoryError")
}

Check your imagen too, whether there is a high resolution needed.

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