0

我正在尝试将 SupportMapFragment 类与 Google Maps API v2 一起使用。但我一直遇到这个错误。我已导入 google-play-services_lib 项目,并将其添加到我的 Java 构建路径中。

    03-29 23:58:09.893: E/AndroidRuntime(26163): FATAL EXCEPTION: main
    03-29 23:58:09.893: E/AndroidRuntime(26163): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.yo/com.example.yo.MainActivity}: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1830)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1851)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.app.ActivityThread.access$1500(ActivityThread.java:132)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1038)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.os.Handler.dispatchMessage(Handler.java:99)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.os.Looper.loop(Looper.java:150)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.app.ActivityThread.main(ActivityThread.java:4277)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at java.lang.reflect.Method.invokeNative(Native Method)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at java.lang.reflect.Method.invoke(Method.java:507)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at dalvik.system.NativeStart.main(Native Method)
    03-29 23:58:09.893: E/AndroidRuntime(26163): Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class fragment
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:587)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:250)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.app.Activity.setContentView(Activity.java:1712)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at com.example.yo.MainActivity.onCreate(MainActivity.java:11)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1072)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1794)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    ... 11 more
    03-29 23:58:09.893: E/AndroidRuntime(26163): Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f060000
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.content.res.Resources.getValue(Resources.java:901)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.content.res.Resources.openRawResource(Resources.java:826)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.content.res.Resources.openRawResource(Resources.java:808)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at maps.af.w.a(Unknown Source)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at maps.z.ab.a(Unknown Source)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at maps.z.ag.a(Unknown Source)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at maps.z.ag.a(Unknown Source)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at maps.z.bw.a(Unknown Source)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at maps.z.r.onCreateView(Unknown Source)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at com.google.android.gms.maps.internal.IMapFragmentDelegate$Stub.onTransact(IMapFragmentDelegate.java:107)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.os.Binder.transact(Binder.java:279)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at com.google.android.gms.internal.e$4.a(Unknown Source)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at com.google.android.gms.internal.e.a(Unknown Source)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at com.google.android.gms.internal.e.onCreateView(Unknown Source)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1460)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:884)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1066)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1168)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:280)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
    03-29 23:58:09.893: E/AndroidRuntime(26163):    ... 20 more
    03-29 23:58:09.933: D/dalvikvm(26163): GC_CONCURRENT freed 367K, 45% free 3282K/5959K, external 0K/0K, paused 6ms+5ms
    03-29 23:58:11.764: I/Process(26163): Sending signal. PID: 26163 SIG: 9

这是我的清单:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.yo"
        android:versionCode="1"
        android:versionName="1.0" >

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

        <uses-permission
            android:name="com.example.yo.permission.MAPS_RECEIVE"/>
        <uses-permission
            android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
        <uses-permission
            android:name="android.permission.INTERNET"/>
        <uses-permission
            android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
        <uses-feature
            android:glEsVersion="0x00020000"
            android:required="true"/> 

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

        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.example.yo.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>
            <uses-library android:name="com.google.android.maps" />
             <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="the key"/>
        </application>
    </manifest>

我的主要活动:

    package com.example.yo;

    import android.os.Bundle;
    import android.support.v4.app.FragmentActivity;

    public class MainActivity extends FragmentActivity {

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

和 XML:

    <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=".MainActivity" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:text="@string/hello_world" />
        <fragment
            android:id="@+id/map"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            class="com.google.android.gms.maps.SupportMapFragment"/>

    </RelativeLayout>

我在这里想念什么?

4

1 回答 1

1

从 manifast 文件中删除这行代码:

 <uses-library android:name="com.google.android.maps" />

谷歌地图 API V2 不需要它。

它与您当前的问题无关,但您还需要添加以下权限:

<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" />

并且您需要以其他方式添加谷歌库,请在我写的博客文章中阅读更多信息:

谷歌地图 API V2

于 2013-03-29T18:43:56.697 回答