0

我没有显示任何图钉;我只是想显示一张地图,但是当我尝试开始一项活动时,它会被强制关闭并给出异常:

显示某种类型的片段类错误或二进制错误

清单文件是:

Mani.xml

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

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

    <permission
          android:name="in.wptrafficanalyzer.LocationGoogleMapV2Demo.permission.MAPS_RECEIVE"
          android:protectionLevel="signature"/>

    <uses-permission android:name="in.wptrafficanalyzer.LocationGoogleMapV2Demo.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"/>

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="in.wptrafficanalyzer.locationgooglemapv2demo.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="AIzaSyAdupvz6Hpet0O5OxfAg8n-OrrFPK8_JZ4"/>
    </application>
</manifest>

例外

04-11 18:07:42.476: E/AndroidRuntime(13119): FATAL EXCEPTION: main
04-11 18:07:42.476: E/AndroidRuntime(13119): java.lang.RuntimeException: Unable to start activity ComponentInfo{in.wptrafficanalyzer.locationgooglemapv2demo/in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.app.ActivityThread.access$600(ActivityThread.java:140)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.os.Looper.loop(Looper.java:137)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.app.ActivityThread.main(ActivityThread.java:4895)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at java.lang.reflect.Method.invokeNative(Native Method)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at java.lang.reflect.Method.invoke(Method.java:511)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at dalvik.system.NativeStart.main(Native Method)
04-11 18:07:42.476: E/AndroidRuntime(13119): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:306)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.app.Activity.setContentView(Activity.java:1912)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at in.wptrafficanalyzer.locationgooglemapv2demo.MainActivity.onCreate(MainActivity.java:12)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.app.Activity.performCreate(Activity.java:5163)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2061)
04-11 18:07:42.476: E/AndroidRuntime(13119):     ... 11 more
04-11 18:07:42.476: E/AndroidRuntime(13119): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.SupportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
04-11 18:07:42.476: E/AndroidRuntime(13119):     ... 21 more
04-11 18:07:42.476: E/AndroidRuntime(13119): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment
04-11 18:07:42.476: E/AndroidRuntime(13119):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
04-11 18:07:42.476: E/AndroidRuntime(13119):     at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
04-11 18:07:42.476: E/AndroidRuntime(13119):     ... 24 more
4

3 回答 3

1

您的 mainfest 显示 minSDK=8,这意味着您必须使用 SupportMapFragment 而不是 Fragment:

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

请参阅下面的我的博客文章。我试图总结所有关于使用 Google Maps API V2 for Android 构建应用程序所需的内容。

  1. Maps API V2 问题的解决方案(使用 google_play_services_lib)。
  2. 使用 Maps API V2 for minSDK=8 (Android 2.2 Froyo) 创建一个 Android 应用程序。
  3. 使用 Maps API V2 for minSDK=11 (Android 3.0 HoneyComb) 创建一个 Android 应用程序。
于 2013-05-05T12:35:23.727 回答
0
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCzlSw2fSYPx--CgFpk0LBp8Ofm23glhCs"/>
        <meta-data 
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

在清单文件中添加这些行

于 2014-07-10T12:13:46.927 回答
0

要添加SupportMapFragment到您的项目中,您需要添加google-support-v4库和 Google 地图库。

检查 Stack Overflow 问题Google Maps Fragment doesn't load

于 2013-04-11T13:08:32.033 回答