在谷歌地图api v2中膨胀片段异常

时间:2014-03-18 16:54:21

标签: java android google-maps android-fragments

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

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

这是活动的布局文件,甚至还添加了对播放服务项目的引用 并输入了api键,但仍显示错误。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.helloloc"
android:versionCode="1"
android:versionName="1.0" >
 <uses-sdk
    android:minSdkVersion="19"
    android:targetSdkVersion="19" />
<permission
    android:name="com.helloloc.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

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

<uses-permission android:name="com.helloloc.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" >
          <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="key" />
     <activity
        android:name="com.helloloc.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>
      </application></manifest>

这是包含api密钥的清单文件

并且log cat异常是

03-18 13:02:06.579: W/asset(820): Copying FileAsset 0x74d4a850 (zip:/data/app/com.helloloc-1.apk:/resources.arsc) to buffer size 141712 to make it aligned.
03-18 13:02:06.919: W/dalvikvm(820): threadid=1: thread exiting with uncaught exception (group=0x416ebe18)
03-18 13:02:06.929: E/AndroidRuntime(820): FATAL EXCEPTION: main
03-18 13:02:06.929: E/AndroidRuntime(820): Process: com.helloloc, PID: 820
03-18 13:02:06.929: E/AndroidRuntime(820): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.helloloc/com.helloloc.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2596)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2653)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.app.ActivityThread.access$800(ActivityThread.java:156)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1355)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.os.Handler.dispatchMessage(Handler.java:102)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.os.Looper.loop(Looper.java:157)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.app.ActivityThread.main(ActivityThread.java:5872)
03-18 13:02:06.929: E/AndroidRuntime(820):  at java.lang.reflect.Method.invokeNative(Native Method)
03-18 13:02:06.929: E/AndroidRuntime(820):  at java.lang.reflect.Method.invoke(Method.java:515)
03-18 13:02:06.929: E/AndroidRuntime(820):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1069)
03-18 13:02:06.929: E/AndroidRuntime(820):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:885)
03-18 13:02:06.929: E/AndroidRuntime(820):  at dalvik.system.NativeStart.main(Native Method)
03-18 13:02:06.929: E/AndroidRuntime(820): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
03-18 13:02:06.929: E/AndroidRuntime(820):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:375)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.app.Activity.setContentView(Activity.java:1997)
03-18 13:02:06.929: E/AndroidRuntime(820):  at com.helloloc.MainActivity.onCreate(MainActivity.java:21)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.app.Activity.performCreate(Activity.java:5312)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1111)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2552)
03-18 13:02:06.929: E/AndroidRuntime(820):  ... 11 more
03-18 13:02:06.929: E/AndroidRuntime(820): Caused by: java.lang.SecurityException: The Maps API requires the additional following permissions to be set in the AndroidManifest.xml to ensure a correct behavior:
03-18 13:02:06.929: E/AndroidRuntime(820): <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>  
03-18 13:02:06.929: E/AndroidRuntime(820):  at maps.e.ch.a(Unknown Source)
03-18 13:02:06.929: E/AndroidRuntime(820):  at maps.e.ay.a(Unknown Source)
03-18 13:02:06.929: E/AndroidRuntime(820):  at maps.e.ay.a(Unknown Source)
03-18 13:02:06.929: E/AndroidRuntime(820):  at maps.e.al.a(Unknown Source)
03-18 13:02:06.929: E/AndroidRuntime(820):  at maps.e.bg.a(Unknown Source)
03-18 13:02:06.929: E/AndroidRuntime(820):  at maps.e.bf.a(Unknown Source)
03-18 13:02:06.929: E/AndroidRuntime(820):  at eio.onTransact(SourceFile:107)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.os.Binder.transact(Binder.java:361)
03-18 13:02:06.929: E/AndroidRuntime(820):  at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source)
03-18 13:02:06.929: E/AndroidRuntime(820):  at com.google.android.gms.maps.MapFragment$a.onCreateView(Unknown Source)
03-18 13:02:06.929: E/AndroidRuntime(820):  at com.google.android.gms.dynamic.a$4.b(Unknown Source)
03-18 13:02:06.929: E/AndroidRuntime(820):  at com.google.android.gms.dynamic.a.a(Unknown Source)
03-18 13:02:06.929: E/AndroidRuntime(820):  at com.google.android.gms.dynamic.a.onCreateView(Unknown Source)
03-18 13:02:06.929: E/AndroidRuntime(820):  at com.google.android.gms.maps.MapFragment.onCreateView(Unknown Source)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.app.Fragment.performCreateView(Fragment.java:1777)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:875)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1084)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.app.FragmentManagerImpl.addFragment(FragmentManager.java:1201)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.app.Activity.onCreateView(Activity.java:4867)
03-18 13:02:06.929: E/AndroidRuntime(820):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
03-18 13:02:06.929: E/AndroidRuntime(820):  ... 21 more
03-18 13:02:09.162: D/Process(820): killProcess, pid=820
03-18 13:02:09.162: D/Process(820): com.android.internal.os.RuntimeInit$UncaughtHandler.uncaughtException:131 java.lang.ThreadGroup.uncaughtException:693 java.lang.ThreadGroup.uncaughtException:690 

提前致谢

1 个答案:

答案 0 :(得分:0)

  

引起:java.lang.SecurityException:Maps API需要   在AndroidManifest.xml中设置其他以下权限   确保正确的行为:03-18 13:02:06.929:   E / AndroidRuntime(820):03-18   13:02:06.929:E / AndroidRuntime(820):at maps.e.ch.a(Unknown Source)\

您需要添加此

 <uses-permission
 android:name="android.permission.ACCESS_NETWORK_STATE"/>
清单文件中的

您需要以下作为应用程序标记的子项

<meta-data     
android:name="com.google.android.gms.version"    
android:value="@integer/google_play_services_version" />