0

我正在尝试使用 SherlockActivtiyBar 在片段内开发 Google Android Map v2。

我有这个错误:

04-12 10:01:26.830: E/AndroidRuntime(1089): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.it.michele.ab.map/it.michele.prova.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment

你能帮助我吗?

我做错了什么?

这是我的 Eclipse 项目:

http://www.michelepierri.it/project.zip

这是我的代码:
SherlockMapFragment.java

package com.actionbarsherlock.app;

    import android.app.Activity;
    import android.support.v4.app.Watson.OnCreateOptionsMenuListener;
    import android.support.v4.app.Watson.OnOptionsItemSelectedListener;
    import android.support.v4.app.Watson.OnPrepareOptionsMenuListener;

    import com.actionbarsherlock.app.SherlockFragmentActivity;
    import com.actionbarsherlock.internal.view.menu.MenuItemWrapper;
    import com.actionbarsherlock.internal.view.menu.MenuWrapper;
    import com.actionbarsherlock.view.Menu;
    import com.actionbarsherlock.view.MenuInflater;
    import com.actionbarsherlock.view.MenuItem;
    import com.google.android.gms.maps.SupportMapFragment;

    public class SherlockMapFragment extends SupportMapFragment implements OnCreateOptionsMenuListener, OnPrepareOptionsMenuListener, OnOptionsItemSelectedListener {
        private SherlockFragmentActivity mActivity;

        public SherlockFragmentActivity getSherlockActivity() {
            return mActivity;
        }

        @Override
        public void onAttach(Activity activity) {
            if (!(activity instanceof SherlockFragmentActivity)) {
                throw new IllegalStateException(getClass().getSimpleName() + " must be attached to a SherlockFragmentActivity.");
            }
            mActivity = (SherlockFragmentActivity)activity;

            super.onAttach(activity);
        }

        @Override
        public void onDetach() {
            mActivity = null;
            super.onDetach();
        }

        @Override
        public final void onCreateOptionsMenu(android.view.Menu menu, android.view.MenuInflater inflater) {
            onCreateOptionsMenu(new MenuWrapper(menu), mActivity.getSupportMenuInflater());
        }

        @Override
        public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
            //Nothing to see here.
        }

        @Override
        public final void onPrepareOptionsMenu(android.view.Menu menu) {
            onPrepareOptionsMenu(new MenuWrapper(menu));
        }

        @Override
        public void onPrepareOptionsMenu(Menu menu) {
            //Nothing to see here.
        }

        @Override
        public final boolean onOptionsItemSelected(android.view.MenuItem item) {
            return onOptionsItemSelected(new MenuItemWrapper(item));
        }

        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            //Nothing to see here.
            return false;
        }
    }

MainActivity.java

   package it.michele.prova;

import com.actionbarsherlock.app.SherlockFragmentActivity;

import android.os.Bundle;
import android.app.Activity;
//import android.view.Menu;
import com.actionbarsherlock.view.*;

import com.example.it.michele.ab.map.R;
import com.example.it.michele.ab.map.R.layout;
import com.example.it.michele.ab.map.R.menu;
//import com.google.android.gms.maps.*;

public class MainActivity extends SherlockFragmentActivity {

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

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, (android.view.Menu) menu);
        return true;
    }

}

activity_main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <fragment
        android:id="@+id/fragment_map"
        android:name=".ui.fragments.MapFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:tag="tag_fragment_map" />

    <fragment
        android:id="@+id/fragment_help"
        android:name=".ui.fragments.HelpFragment"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:tag="tag_fragment_help" />
</FrameLayout>

在此处输入图像描述

4

2 回答 2

0

我花了几天时间试图解决这个问题。就我而言,我没有在我的 android 清单中引用 open GL es v2 - 一旦我把它放在那里,错误就消失了,我的地图也出现了。如果该语句尚不存在,请将其添加到您的 android 清单权限中-这可能会为您解决。

于 2013-06-15T16:01:52.597 回答
0

通常,如果您fragment/class not found error在使用地图时收到消息,那么您的问题可能是因为缺少对该库的良好参考,google-play-services因为MapFragment/SupportMapFragment是该库的一部分:

检查你的Android Dependencies文件夹是否(blue)google-play-services (orange)里面,你会发现有这个类的com.google.android.gms.maps包:(green)MapFragment(red)

在此处输入图像描述

如果不是这种情况,您可以查看我写的这篇博文的前 3 个步骤,以了解如何正确引用这个包:

谷歌地图 API V2

于 2013-04-12T08:13:52.900 回答