我正在尝试查看地图并收到错误消息。 我喜欢在教程中,但我仍然得到同样的错误。
我的应用程序的主要类
mainActivity.java
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
基于片段的视图
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"/>
和我的清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="com.example.test.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<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=".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="AIzaSyBYc19VLUKQTeR6hREcl2REggCO6KPFEk4" />
</application>
</manifest>
我的应用日志
10-20 01:58:00.913: E/AndroidRuntime(16234): FATAL EXCEPTION: main
10-20 01:58:00.913: E/AndroidRuntime(16234): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.test/com.example.test.MainActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2062)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2087)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.app.ActivityThread.access$600(ActivityThread.java:133)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1198)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.os.Handler.dispatchMessage(Handler.java:99)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.os.Looper.loop(Looper.java:137)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.app.ActivityThread.main(ActivityThread.java:4803)
10-20 01:58:00.913: E/AndroidRuntime(16234): at java.lang.reflect.Method.invokeNative(Native Method)
10-20 01:58:00.913: E/AndroidRuntime(16234): at java.lang.reflect.Method.invoke(Method.java:511)
10-20 01:58:00.913: E/AndroidRuntime(16234): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
10-20 01:58:00.913: E/AndroidRuntime(16234): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
10-20 01:58:00.913: E/AndroidRuntime(16234): at dalvik.system.NativeStart.main(Native Method)
10-20 01:58:00.913: E/AndroidRuntime(16234): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
10-20 01:58:00.913: E/AndroidRuntime(16234): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:258)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.app.Activity.setContentView(Activity.java:1867)
10-20 01:58:00.913: E/AndroidRuntime(16234): at com.example.test.MainActivity.onCreate(MainActivity.java:22)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.app.Activity.performCreate(Activity.java:5008)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2026)
10-20 01:58:00.913: E/AndroidRuntime(16234): ... 11 more
10-20 01:58:00.913: E/AndroidRuntime(16234): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 6111000 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" />
10-20 01:58:00.913: E/AndroidRuntime(16234): at com.google.android.gms.common.GooglePlayServicesUtil.E(Unknown Source)
10-20 01:58:00.913: E/AndroidRuntime(16234): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
10-20 01:58:00.913: E/AndroidRuntime(16234): at com.google.android.gms.maps.internal.u.S(Unknown Source)
10-20 01:58:00.913: E/AndroidRuntime(16234): at com.google.android.gms.maps.internal.u.R(Unknown Source)
10-20 01:58:00.913: E/AndroidRuntime(16234): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
10-20 01:58:00.913: E/AndroidRuntime(16234): at com.google.android.gms.maps.MapFragment$b.my(Unknown Source)
10-20 01:58:00.913: E/AndroidRuntime(16234): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
10-20 01:58:00.913: E/AndroidRuntime(16234): at com.google.android.gms.dynamic.a.a(Unknown Source)
10-20 01:58:00.913: E/AndroidRuntime(16234): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
10-20 01:58:00.913: E/AndroidRuntime(16234): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.app.Activity.onCreateView(Activity.java:4663)
10-20 01:58:00.913: E/AndroidRuntime(16234): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
答案 0 :(得分:0)
错误说
引起:java.lang.IllegalStateException:应用程序的AndroidManifest.xml中的元数据标记没有正确的值。预期6111000但找到0.您必须在元素中包含以下声明:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
将<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
添加到<application>
标记内的清单文件中。