Java 抽屉布局+;谷歌地图导致崩溃

Java 抽屉布局+;谷歌地图导致崩溃,java,android,google-maps,android-layout,android-fragments,Java,Android,Google Maps,Android Layout,Android Fragments,我被困在抽屉布局中,当按下抽屉项目1时,我试图实现谷歌地图。 这与我在这里发现的类似: 我试图复制他所做的,这把我推向了正确的方向 已更新 我已经将“SetupMapiFneed”和“SetUpMap”移动到MapFragment中,并从类中删除了static。 谷歌地图现在可以工作,但在尝试导航到抽屉导航中的片段后崩溃 有人知道怎么帮我吗?我非常感激 基本材料 @Override protected void onCreate(Bundle savedInstanceState) {

我被困在抽屉布局中,当按下抽屉项目1时,我试图实现谷歌地图。 这与我在这里发现的类似:

我试图复制他所做的,这把我推向了正确的方向

已更新

我已经将“SetupMapiFneed”和“SetUpMap”移动到MapFragment中,并从类中删除了static。 谷歌地图现在可以工作,但在尝试导航到抽屉导航中的片段后崩溃

有人知道怎么帮我吗?我非常感激

基本材料

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

    mTitle = mDrawerTitle = getTitle();
    mMenuTitles = getResources().getStringArray(R.array.menu_array);
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this,
            R.layout.drawer_list_item, mMenuTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mDrawerToggle = new ActionBarDrawerToggle(
            this,                  /* host Activity */
            mDrawerLayout,         /* DrawerLayout object */
            R.drawable.ic_drawer,  /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open,  /* "open drawer" description for accessibility */
            R.string.drawer_close  /* "close drawer" description for accessibility */
            ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

    if (savedInstanceState == null) {
        selectItem(0);
    }
}
我的地图碎片(抽屉项目1)

我的信息\u fragment.xml

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

<TextView
    android:id="@+id/textViewTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="20dp"
    android:paddingTop="20dp"
    android:text="Title 2"
    android:textStyle="bold" />

    <TextView
        android:id="@+id/textViewDescription"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:paddingTop="10dp"
        android:paddingRight="20dp"
        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&apos;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:layout_weight="0.29" />

我的地图\u fragment.xml

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

<TextView
    android:id="@+id/textViewTitle"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingLeft="20dp"
    android:paddingTop="20dp"
    android:text="Title 2"
    android:textStyle="bold" />

    <TextView
        android:id="@+id/textViewDescription"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="20dp"
        android:paddingTop="10dp"
        android:paddingRight="20dp"
        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&apos;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum." />
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<fragment
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:layout_weight="0.29" />


尝试修改代码,如 添加fragmentManager.executePendingTransactions();犯罪后

Fragment mapFragment;
Fragment fragment;
private void selectItem(int position) {
    FragmentManager fragmentManager = getFragmentManager();

    if (position == 0) {
        if (mapFragment == null) {
            mapFragment = new MapFragment();
        }
        Bundle args = new Bundle();

        args.putInt(MapFragment.ARG_NUMBER, position);
        mapFragment.setArguments(args);

        fragmentManager.beginTransaction().replace(R.id.content_frame, mapFragment).commit();

    } else if (position == 1) {
        if (fragment == null) {
            fragment = new InformationFragment();
        }
        Bundle args = new Bundle();

        args.putInt(InformationFragment.ARG_NUMBER, position);
        fragment.setArguments(args);

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

   fragmentManager.executePendingTransactions();
    // update selected item and title, then close the drawer
    mDrawerList.setItemChecked(position, true);
    setTitle(mMenuTitles[position]);
    mDrawerLayout.closeDrawer(mDrawerList);
}

我添加了崩溃日志,说它有重复的id。是的,你的意思是“由”引起的,对吗?你知道如何解决这个问题吗?检查答案并根据更改更新代码。我在更改后添加了一个崩溃日志。应用程序现在立即崩溃XD