1

首先,在过去我能够运行谷歌地图 v2

现在我得到了这个例外:

06-12 21:31:14.289: E/AndroidRuntime(17491): FATAL EXCEPTION: main
06-12 21:31:14.289: E/AndroidRuntime(17491): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.williamroma.example/com.williamroma.example.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.app.ActivityThread.access$1500(ActivityThread.java:121)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.os.Handler.dispatchMessage(Handler.java:99)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.os.Looper.loop(Looper.java:130)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.app.ActivityThread.main(ActivityThread.java:3701)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at java.lang.reflect.Method.invokeNative(Native Method)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at java.lang.reflect.Method.invoke(Method.java:507)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at dalvik.system.NativeStart.main(Native Method)
06-12 21:31:14.289: E/AndroidRuntime(17491): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:581)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:227)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.app.Activity.setContentView(Activity.java:1657)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at com.williamroma.example.MainActivity.onCreate(MainActivity.java:11)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
06-12 21:31:14.289: E/AndroidRuntime(17491):    ... 11 more
06-12 21:31:14.289: E/AndroidRuntime(17491): Caused by: java.lang.ClassNotFoundException: android.view.fragment in loader dalvik.system.PathClassLoader[/data/app/com.williamroma.example-1.apk]
06-12 21:31:14.289: E/AndroidRuntime(17491):    at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.view.LayoutInflater.createView(LayoutInflater.java:471)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:549)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
06-12 21:31:14.289: E/AndroidRuntime(17491):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
06-12 21:31:14.289: E/AndroidRuntime(17491):    ... 19 more

最重要的是

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.williamroma.example"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <permission
        android:name="com.williamroma.example.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="com.williamroma.example.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="XXXXXXXXXXXXXXXXXXXXXXXXXX" />
    </application>

</manifest>

我的活动是:

public class MainActivity extends Activity {

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

xml

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/map"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:name="com.google.android.gms.maps.MapFragment"/>

我将 android 目标设置为 2.2 google api,我正在我的手机 2.3 上对其进行测试

请帮忙

4

1 回答 1

3

Your min sdk is 8. You should use Support Fragment.

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

Your activity must extend FragmentActivity

SupportMapFragment fm = (SupportMapFragment)  getSupportFragmentManager().findFragmentById(R.id.map);
GoogleMap mMap = fm.getMap(); 

Make sure you have added support library

Also make sure you imported the below

import android.support.v4.app.FragmentActivity;  
import com.google.android.gms.maps.SupportMapFragment;    
于 2013-06-11T18:31:45.787 回答