我知道以前曾经问过,但我找不到任何解决方案。
我试图在我的Android应用程序中包含一个谷歌地图,但它一直崩溃:
11-14 14:58:51.864: D/dalvikvm(1604): Late-enabling CheckJNI
11-14 14:58:51.914: D/AndroidRuntime(1604): Shutting down VM
11-14 14:58:51.914: W/dalvikvm(1604): threadid=1: thread exiting with uncaught exception (group=0x41f7cb90)
11-14 14:58:51.924: E/AndroidRuntime(1604): FATAL EXCEPTION: main
11-14 14:58:51.924: E/AndroidRuntime(1604): Process: com.example.testmaps, PID: 1604
11-14 14:58:51.924: E/AndroidRuntime(1604): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.testmaps/com.example.testmaps.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.app.ActivityThread.access$700(ActivityThread.java:135)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.os.Handler.dispatchMessage(Handler.java:102)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.os.Looper.loop(Looper.java:137)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.app.ActivityThread.main(ActivityThread.java:4998)
11-14 14:58:51.924: E/AndroidRuntime(1604): at java.lang.reflect.Method.invokeNative(Native Method)
11-14 14:58:51.924: E/AndroidRuntime(1604): at java.lang.reflect.Method.invoke(Method.java:515)
11-14 14:58:51.924: E/AndroidRuntime(1604): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
11-14 14:58:51.924: E/AndroidRuntime(1604): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
11-14 14:58:51.924: E/AndroidRuntime(1604): at dalvik.system.NativeStart.main(Native Method)
11-14 14:58:51.924: E/AndroidRuntime(1604): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.view.LayoutInflater.inflate(LayoutInflater.java:469)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-14 14:58:51.924: E/AndroidRuntime(1604): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.app.Activity.setContentView(Activity.java:1928)
11-14 14:58:51.924: E/AndroidRuntime(1604): at com.example.testmaps.MainActivity.onCreate(MainActivity.java:12)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.app.Activity.performCreate(Activity.java:5243)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
11-14 14:58:51.924: E/AndroidRuntime(1604): ... 11 more
11-14 14:58:51.924: E/AndroidRuntime(1604): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
11-14 14:58:51.924: E/AndroidRuntime(1604): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
11-14 14:58:51.924: E/AndroidRuntime(1604): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
11-14 14:58:51.924: E/AndroidRuntime(1604): at com.google.android.gms.maps.internal.q.v(Unknown Source)
11-14 14:58:51.924: E/AndroidRuntime(1604): at com.google.android.gms.maps.internal.q.u(Unknown Source)
11-14 14:58:51.924: E/AndroidRuntime(1604): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
11-14 14:58:51.924: E/AndroidRuntime(1604): at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
11-14 14:58:51.924: E/AndroidRuntime(1604): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
11-14 14:58:51.924: E/AndroidRuntime(1604): at com.google.android.gms.dynamic.a.a(Unknown Source)
11-14 14:58:51.924: E/AndroidRuntime(1604): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
11-14 14:58:51.924: E/AndroidRuntime(1604): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.app.Activity.onCreateView(Activity.java:4784)
11-14 14:58:51.924: E/AndroidRuntime(1604): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
11-14 14:58:51.924: E/AndroidRuntime(1604): ... 20 more
的manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.testmaps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="19" />
<permission
android:name="com.example.testmaps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.testmaps.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<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="com.example.testmaps.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="AIzaSyAJPOrFWSi-z9ME1xbevn-Kl7QOYA1h0iE" />
</application>
</manifest>
activity_my_map.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"/>
MainActivity.java
package com.example.testmaps;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my_map);
}
@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, menu);
return true;
}
}
我也尝试将其更改为FragmentActivity,但没有任何运气。
答案 0 :(得分:2)
由于log-cat中的错误说明,您需要添加以下meta-data
标记:
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
在Manifest
文件的应用标记内,它是从上一版本13更新添加到google-play-services
的新要求。