web-dev-qa-db-ja.com

java.lang.IllegalArgumentException:フラグメントFmMenuのID 0x7f090047( "プロジェクト名":id / content)のビューが見つかりません

私が抱えている問題を、私がクライアントのために行っているプロジェクトと共有したかっただけです。

IntroActivityに入り、ボタンを押してMenuActivityに移動すると、クラッシュします。

これがエラーログです:

_02-16 18:49:49.393    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ No view found for id 0x7f090047 (com.wlodsgn.bunbunup:id/linear) for fragment FmMenu{b1e537f0 #0 id=0x7f090047}
02-16 18:49:49.393    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Activity state:
02-16 18:49:49.423    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Local FragmentActivity b1e1d1b8 State:
02-16 18:49:49.423    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ mCreated=falsemResumed=false mStopped=false mReallyStopped=false
02-16 18:49:49.423    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ mLoadersStarted=false
02-16 18:49:49.443    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ FragmentManager misc state:
02-16 18:49:49.443    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ mActivity=com.wlodsgn.bunbunup.MenuActivity@b1e1d1b8
02-16 18:49:49.443    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ mContainer=Android.support.v4.app.FragmentActivity$2@b1e1ed08
02-16 18:49:49.453    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ mCurState=1 mStateSaved=false mDestroyed=false
02-16 18:49:49.453    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ View Hierarchy:
02-16 18:49:49.453    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ com.Android.internal.policy.impl.PhoneWindow$DecorView{b1e23d08 V.E..... ... 0,0-0,0}
02-16 18:49:49.473    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Android.widget.LinearLayout{b1e24280 V.E..... ... 0,0-0,0}
02-16 18:49:49.473    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Android.view.ViewStub{b1e24da8 G.E..... ... 0,0-0,0 #102030e}
02-16 18:49:49.473    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Android.widget.FrameLayout{b1e25038 V.E..... ... 0,0-0,0}
02-16 18:49:49.473    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Android.support.v7.internal.widget.ActionBarOverlayLayout{b1e2db28 V.E..... ... 0,0-0,0 #7f09002f app:id/decor_content_parent}
02-16 18:49:49.483    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Android.support.v7.internal.widget.NativeActionModeAwareLayout{b1e2f758 V.E..... ... 0,0-0,0 #1020002 Android:id/content}
02-16 18:49:49.483    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ [ 02-16 18:49:49.513  1208: 1208 E/FragmentManager ]
    Android.support.v4.widget.DrawerLayout{b1e2c058 VFE..... ... 0,0-0,0 #7f090042 app:id/drawer_layout}
02-16 18:49:49.513    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Android.widget.LinearLayout{b1e1fa90 V.E..... ... 0,0-0,0}
02-16 18:49:49.523    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Android.support.v4.view.ViewPager{b1e29568 VFED.... ... 0,0-0,0 #7f090043 app:id/pager}
02-16 18:49:49.523    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Android.widget.ListView{b1e44148 VFED.VC. ... 0,0-0,0 #7f090044 app:id/listView1}
02-16 18:49:49.523    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Android.widget.ListView{b1dd80b8 VFED.VC. ... 0,0-0,0 #7f090045 app:id/list_slidermenu}
02-16 18:49:49.523    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Android.support.v7.internal.widget.ActionBarContainer{b1e2fcd0 V.ED.... ... 0,0-0,0 #7f090030 app:id/action_bar_container}
02-16 18:49:49.533    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Android.support.v7.widget.Toolbar{b1e30898 V.E..... ... 0,0-0,0 #7f090031 app:id/action_bar}
02-16 18:49:49.533    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Android.widget.ImageButton{b1e39da8 VFED..C. ... 0,0-0,0}
02-16 18:49:49.533    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Android.widget.TextView{b1e28a60 V.ED.... ... 0,0-0,0}
02-16 18:49:49.533    1208-1208/com.wlodsgn.bunbunup E/FragmentManager﹕ Android.support.v7.internal.widget.ActionBarContextView{b1e43a50 G.E..... ... 0,0-0,0 #7f090032 app:id/action_context_bar}
02-16 18:49:49.543    1208-1208/com.wlodsgn.bunbunup D/AndroidRuntime﹕ Shutting down VM
02-16 18:49:49.543    1208-1208/com.wlodsgn.bunbunup W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb1a87ba8)
02-16 18:49:49.573    1208-1208/com.wlodsgn.bunbunup E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.wlodsgn.bunbunup, PID: 1208
    Java.lang.RuntimeException: Unable to start activity ComponentInfo{com.wlodsgn.bunbunup/com.wlodsgn.bunbunup.MenuActivity}: Java.lang.IllegalArgumentException: No view found for id 0x7f090047 (com.wlodsgn.bunbunup:id/linear) for fragment FmMenu{b1e537f0 #0 id=0x7f090047}
            at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2195)
            at Android.app.ActivityThread.handleLaunchActivity(ActivityThread.Java:2245)
            at Android.app.ActivityThread.access$800(ActivityThread.Java:135)
            at Android.app.ActivityThread$H.handleMessage(ActivityThread.Java:1196)
            at Android.os.Handler.dispatchMessage(Handler.Java:102)
            at Android.os.Looper.loop(Looper.Java:136)
            at Android.app.ActivityThread.main(ActivityThread.Java:5017)
            at Java.lang.reflect.Method.invokeNative(Native Method)
            at Java.lang.reflect.Method.invoke(Method.Java:515)
            at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java:779)
            at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:595)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: Java.lang.IllegalArgumentException: No view found for id 0x7f090047 (com.wlodsgn.bunbunup:id/linear) for fragment FmMenu{b1e537f0 #0 id=0x7f090047}
            at Android.app.FragmentManagerImpl.moveToState(FragmentManager.Java:882)
            at Android.app.FragmentManagerImpl.moveToState(FragmentManager.Java:1062)
            at Android.app.BackStackRecord.run(BackStackRecord.Java:684)
            at Android.app.FragmentManagerImpl.execPendingActions(FragmentManager.Java:1447)
            at Android.app.Activity.performStart(Activity.Java:5240)
            at Android.app.ActivityThread.performLaunchActivity(ActivityThread.Java:2168)
            at Android.app.ActivityThread.handleLaunchActivity(ActivityThread.Java:2245)
            at Android.app.ActivityThread.access$800(ActivityThread.Java:135)
            at Android.app.ActivityThread$H.handleMessage(ActivityThread.Java:1196)
            at Android.os.Handler.dispatchMessage(Handler.Java:102)
            at Android.os.Looper.loop(Looper.Java:136)
            at Android.app.ActivityThread.main(ActivityThread.Java:5017)
            at Java.lang.reflect.Method.invokeNative(Native Method)
            at Java.lang.reflect.Method.invoke(Method.Java:515)
            at com.Android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.Java:779)
            at com.Android.internal.os.ZygoteInit.main(ZygoteInit.Java:595)
            at dalvik.system.NativeStart.main(Native Method)
_

これが私の_MenuActivity.Java_です。エラーがあります(ほぼ最後にif (fragment != null) {で始まります

_import Java.util.ArrayList;
import Java.util.List;

import Android.support.v4.app.FragmentPagerAdapter;
import Android.support.v4.view.MenuItemCompat;
import Android.support.v4.view.MenuItemCompat.OnActionExpandListener;
import Android.support.v4.view.ViewPager;
import Android.support.v7.app.ActionBar;
import Android.support.v7.app.ActionBarActivity;
import Android.support.v7.widget.SearchView;
import Android.support.v7.widget.SearchView.OnQueryTextListener;
import Android.view.LayoutInflater;
import Android.view.ViewGroup;
import Android.widget.ArrayAdapter;
import Android.widget.ImageView;
import Android.widget.TextView;
import Android.widget.Toast;

import Android.app.Fragment;
import Android.app.FragmentManager;
import Android.content.res.Configuration;
import Android.content.res.TypedArray;
import Android.os.Bundle;
import Android.support.v4.app.ActionBarDrawerToggle;
import Android.support.v4.widget.DrawerLayout;
import Android.util.Log;
import Android.view.Menu;
import Android.view.MenuItem;
import Android.view.View;
import Android.widget.AdapterView;
import Android.widget.ListView;

/**
 * Created by WiLo on 2/13/2015.
 */
public class MenuActivity extends ActionBarActivity implements OnQueryTextListener, OnActionExpandListener{

    /*private TextView texto;*/

    private DrawerLayout mDrawerLayout;
    private ListView mDrawerList;
    private ActionBarDrawerToggle mDrawerToggle;

    // nav drawer title
    private CharSequence mDrawerTitle;

    // used to store app title
    private CharSequence mTitle;

    // slide menu items
    private String[] navMenuTitles;
    private TypedArray navMenuIcons;

    private ArrayList<NavDrawerItem> navDrawerItems;
    private NavDrawerListAdapter adapter;

    String[] categoria = {
            "Jeans"
    };

    int[] imagenes = {
            R.drawable.veroxjeans1,
            R.drawable.veroxjeans2,
            R.drawable.veroxjeans3,
            R.drawable.veroxjeans4,
            R.drawable.veroxjeans5,
            R.drawable.veroxjeans6,
            R.drawable.veroxjeans7
    };

    SectionsPagerAdapter mSectionsPagerAdapter;
    ViewPager mViewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_menu);

        /*texto = (TextView) findViewById(R.id.texto);*/

        mTitle = mDrawerTitle = getTitle();

        // load slide menu items
        navMenuTitles = getResources().getStringArray(R.array.nav_drawer_items);

        // nav drawer icons from resources
        navMenuIcons = getResources()
                .obtainTypedArray(R.array.nav_drawer_icons);

        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerList = (ListView) findViewById(R.id.list_slidermenu);

        navDrawerItems = new ArrayList<NavDrawerItem>();

        // agregar un nuevo item al menu deslizante
        // Menu
        navDrawerItems.add(new NavDrawerItem(navMenuTitles[0], navMenuIcons.getResourceId(0, -1)));
        // Contacto
        navDrawerItems.add(new NavDrawerItem(navMenuTitles[1], navMenuIcons.getResourceId(1, -1)));
        // Catologo
        //navDrawerItems.add(new NavDrawerItem(navMenuTitles[2], navMenuIcons.getResourceId(2, -1), true, "Estrenos"));
        // old Contacto (Pedidos)
        //navDrawerItems.add(new NavDrawerItem(navMenuTitles[3], navMenuIcons.getResourceId(3, -1)));

        // Recycle the typed array
        navMenuIcons.recycle();

        mDrawerList.setOnItemClickListener(new SlideMenuClickListener());

        // setting the nav drawer list adapter
        adapter = new NavDrawerListAdapter(getApplicationContext(),
                navDrawerItems);
        mDrawerList.setAdapter(adapter);

        // enabling action bar app icon and behaving it as toggle button
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeButtonEnabled(true);

        mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout,
                R.drawable.ic_drawer, //nav menu toggle icon
                R.string.app_name, // nav drawer open - description for accessibility
                R.string.app_name // nav drawer close - description for accessibility
        ) {
            public void onDrawerClosed(View view) {
                getSupportActionBar().setTitle(mTitle);
                // calling onPrepareOptionsMenu() to show action bar icons
                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                getSupportActionBar().setTitle(mDrawerTitle);
                // calling onPrepareOptionsMenu() to hide action bar icons
                invalidateOptionsMenu();
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);

        if (savedInstanceState == null) {
            // on first time display view for first nav item
            displayView(0);
        }

        //lista
        ListView lista = (ListView) findViewById(R.id.listView1);
        ArrayAdapter adapter = new ArrayAdapter(this, Android.R.layout.simple_list_item_1, categoria );
        lista.setAdapter(adapter);

        //galeria de imagenes

        mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

        mViewPager = (ViewPager) findViewById(R.id.pager);
        mSectionsPagerAdapter.addfragments(PlaceholderFragment.newInstance(imagenes[0]));
        mSectionsPagerAdapter.addfragments(PlaceholderFragment.newInstance(imagenes[1]));
        mSectionsPagerAdapter.addfragments(PlaceholderFragment.newInstance(imagenes[2]));
        mSectionsPagerAdapter.addfragments(PlaceholderFragment.newInstance(imagenes[3]));
        mSectionsPagerAdapter.addfragments(PlaceholderFragment.newInstance(imagenes[4]));
        mSectionsPagerAdapter.addfragments(PlaceholderFragment.newInstance(imagenes[5]));
        mSectionsPagerAdapter.addfragments(PlaceholderFragment.newInstance(imagenes[6]));

        mViewPager.setAdapter(mSectionsPagerAdapter);

    }

    @Override
    public boolean onMenuItemActionExpand(MenuItem menuItem) {
        Toast.makeText(getApplicationContext(), "Abriendo Busqueda", Toast.LENGTH_SHORT).show();
        return true;
    }

    @Override
    public boolean onMenuItemActionCollapse(MenuItem menuItem) {
        Toast.makeText(getApplicationContext(), "Cerrando Busqueda", Toast.LENGTH_SHORT).show();
        return true;
    }

    @Override
    public boolean onQueryTextSubmit(String s) {
        /*texto.setText("Buscando...\n\n" + s);*/
        return false;
    }

    @Override
    public boolean onQueryTextChange(String s) {
        /*texto.setText(" \n\n" + s);*/
        return false;
    }

    /**
     * Slide menu item click listener
     * */
    private class SlideMenuClickListener implements
            ListView.OnItemClickListener {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                                long id) {
            // display view for selected nav drawer item
            displayView(position);
        }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu, menu);

        MenuItem searchItem = menu.findItem(R.id.menu3_buscar);

        SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
        searchView.setOnQueryTextListener(this);

        MenuItemCompat.setOnActionExpandListener(searchItem, this);

        return super.onCreateOptionsMenu(menu);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Pass the event to ActionBarDrawerToggle, if it returns
        // true, then it has handled the app icon touch event
        if (mDrawerToggle.onOptionsItemSelected(item)) {
            return true;
        }
        // Handle your other action bar items...

        return super.onOptionsItemSelected(item);
    }

    /**
     * Diplaying fragment view for selected nav drawer list item
     * */
    private void displayView(int position) {
        // update the main content by replacing fragments
        Fragment fragment = null;
        switch (position) {
            case 0:
                fragment = new FmMenu();
                break;
            case 1:
                fragment = new FmContacto();
                break;

            default:
                break;
        }

        if (fragment != null) {
            FragmentManager fragmentManager = getFragmentManager();
            fragmentManager.beginTransaction()
                    .replace(R.id.linear, fragment).commit();

            // update selected item and title, then close the drawer
            mDrawerList.setItemChecked(position, true);
            mDrawerList.setSelection(position);
            setTitle(navMenuTitles[position]);
            mDrawerLayout.closeDrawer(mDrawerList);
        } else {
            // error in creating fragment
            Log.e("BunBunUp", "MenuActivity - Error cuando se creo el fragment");
        }
    }

    @Override
    public void setTitle(CharSequence title) {
        mTitle = title;
        getSupportActionBar().setTitle(mTitle);
    }

    /**
     * When using the ActionBarDrawerToggle, you must call it during
     * onPostCreate() and onConfigurationChanged()...
     */

    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);
        // Sync the toggle state after onRestoreInstanceState has occurred.
        mDrawerToggle.syncState();
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // Pass any configuration change to the drawer toggle
        mDrawerToggle.onConfigurationChanged(newConfig);
    }

    public class SectionsPagerAdapter extends FragmentPagerAdapter {

        List<Android.support.v4.app.Fragment> fragmentos;
        public SectionsPagerAdapter(Android.support.v4.app.FragmentManager fm) {
            super(fm);
            fragmentos = new ArrayList<Android.support.v4.app.Fragment>();
        }

        public void addfragments(Android.support.v4.app.Fragment xfragment){
            fragmentos.add(xfragment);
        }


        @Override
        public Android.support.v4.app.Fragment getItem(int position) {
            return fragmentos.get(position);
        }

        @Override
        public int getCount() {
            return fragmentos.size();
        }
    }


    public static class PlaceholderFragment extends Android.support.v4.app.Fragment {

        private static final String ARG_IMAGE = "imagen";
        private int imagen;

        public static PlaceholderFragment newInstance(int imagen) {
            PlaceholderFragment fragment = new PlaceholderFragment();
            Bundle args = new Bundle();
            args.putInt(ARG_IMAGE, imagen);
            fragment.setArguments(args);
            fragment.setRetainInstance(true);
            return fragment;
        }

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            if(getArguments() != null) {
                imagen = getArguments().getInt(ARG_IMAGE);
            }
        }

        public PlaceholderFragment() {
        }

        @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;
        }
    }

}
_

MenuActivityにリンクされている残りのファイル(必要な場合)は次のとおりです

FmMenu.Java

_import Android.app.Fragment;
import Android.os.Bundle;
import Android.view.LayoutInflater;
import Android.view.View;
import Android.view.ViewGroup;

/**
 * Created by WiLo on 2/13/2015.
 */
public class FmMenu extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.lay_menufragment, container, false);

        return rootView;
    }
}
_

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.support.v4.view.ViewPager
            Android:id="@+id/pager"
            Android:layout_width="match_parent"
            Android:layout_height="265dp"
            tools:context=".MenuActivity" />

        <ListView
            Android:layout_width="match_parent"
            Android:layout_height="wrap_content"
            Android:id="@+id/listView1"
            Android:layout_gravity="center_horizontal" />

    </LinearLayout>

    <!-- Listview to display slider menu -->
    <ListView
        Android:id="@+id/list_slidermenu"
        Android:layout_width="240dp"
        Android:layout_height="match_parent"
        Android:layout_gravity="start"
        Android:choiceMode="singleChoice"
        Android:divider="@color/list_divider"
        Android:dividerHeight="1dp"
        Android:listSelector="@drawable/list_selector"
        Android:background="@color/list_background"/>
</Android.support.v4.widget.DrawerLayout>
_

fragment_menu.xml

_<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    tools:context=".MenuActivity$PlaceholderFragment"
    Android:id="@+id/linear">

    <ImageView
        Android:layout_width="fill_parent"
        Android:layout_height="fill_parent"
        Android:id="@+id/imageView1"
        Android:layout_alignParentTop="true"
        Android:layout_alignParentLeft="true"
        Android:layout_alignParentStart="true" />
</RelativeLayout>
_

lay_menufragment.xml

_<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
    Android:orientation="vertical" Android:layout_width="match_parent"
    Android:layout_height="match_parent">

</LinearLayout>
_

新しいエラーログ:

_02-17 09:41:20.480      917-917/com.wlodsgn.bunbunup W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb1ad9ba8)
02-17 09:41:20.560      917-917/com.wlodsgn.bunbunup E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.wlodsgn.bunbunup, PID: 917
    Java.lang.OutOfMemoryError
            at Android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
            at Android.graphics.BitmapFactory.decodeStream(BitmapFactory.Java:587)
            at Android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.Java:422)
            at Android.graphics.drawable.Drawable.createFromResourceStream(Drawable.Java:840)
            at Android.content.res.Resources.loadDrawable(Resources.Java:2110)
            at Android.content.res.Resources.getDrawable(Resources.Java:700)
            at Android.widget.ImageView.resolveUri(ImageView.Java:638)
            at Android.widget.ImageView.setImageResource(ImageView.Java:367)
            at com.wlodsgn.bunbunup.MenuActivity$PlaceholderFragment.onCreateView(MenuActivity.Java:345)
            at Android.support.v4.app.Fragment.performCreateView(Fragment.Java:1786)
            at Android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.Java:947)
            at Android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.Java:1126)
            at Android.support.v4.app.BackStackRecord.run(BackStackRecord.Java:739)
            at Android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.Java:1489)
            at Android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.Java:486)
            at Android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.Java:141)
            at Android.support.v4.view.ViewPager.populate(ViewPager.Java:1073)
            at Android.support.v4.view.ViewPager.populate(ViewPager.Java:919)
            at Android.support.v4.view.ViewPager.onMeasure(ViewPager.Java:1441)
            at Android.view.View.measure(View.Java:16497)
            at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5125)
            at Android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.Java:1404)
            at Android.widget.LinearLayout.measureVertical(LinearLayout.Java:695)
            at Android.widget.LinearLayout.onMeasure(LinearLayout.Java:588)
            at Android.view.View.measure(View.Java:16497)
            at Android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.Java:851)
            at Android.view.View.measure(View.Java:16497)
            at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5125)
            at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:310)
            at Android.view.View.measure(View.Java:16497)
            at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5125)
            at Android.support.v7.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.Java:453)
            at Android.view.View.measure(View.Java:16497)
            at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5125)
            at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:310)
            at Android.view.View.measure(View.Java:16497)
            at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5125)
            at Android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.Java:1404)
            at Android.widget.LinearLayout.measureVertical(LinearLayout.Java:695)
            at Android.widget.LinearLayout.onMeasure(LinearLayout.Java:588)
            at Android.view.View.measure(View.Java:16497)
            at Android.view.ViewGroup.measureChildWithMargins(ViewGroup.Java:5125)
            at Android.widget.FrameLayout.onMeasure(FrameLayout.Java:310)
            at com.Android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.Java:2291)
            at Android.view.View.measure(View.Java:16497)
            at Android.view.ViewRootImpl.performMeasure(ViewRootImpl.Java:1916)
            at Android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.Java:1113)
            at Android.view.ViewRootImpl.performTraversals(ViewRootImpl.Java:1295)
            at Android.view.ViewRootImpl.doTraversal(ViewRootImpl.Java:1000)
            at Android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.Java:5670)
            at Android.view.Choreographer$CallbackRecord.run(Choreographer.Java:761)
            at Android.view.Choreographer.doCallbacks(Choreographer.Java:574)
            at Android.view.Choreographer.doFrame(Choreographer.Java:544)
            at Android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.Java:747)
            at Android.os.Handler.handleCallback(Handler.Java:733)
            at Android.os.Handler.dispatchMessage(Handler.Java:95)
            at Android.os.Looper.loop(Looper.Java:136)
_

詳細が必要です。お知らせください

助けていただければ幸いです

6
w_lpz

私は何かを見つけたと思います。

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

ご覧のとおり、レイアウトを置き換えようとしていますR.id.linearフラグメントを使用します。しかし R.id.linearは、fragment_menu.xmlで使用するRelativeLayoutです。 activity_menu.xmlのレイアウトを現在のフラグメントに置き換える必要があります。だから私は提案します:

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

そしてあなたの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">

編集:

新しいエラーの場合:メモリに問題があります。これは、ImageViewsが大きなリソースで埋められている場合によく発生します。したがって、ImageViewを使用する位置は1つだけです。

 @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;
        }

ご覧のとおり、imagenViewはリソースimagenで埋められています

imagenView.setImageResource(imagen);

おそらくそこにOutOfMemoryErrorがあります。解決策として、これを試してください:

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

imagenもチェックし、高解像度が必要かどうかを確認します。

7
Erich