所以我的主屏幕上有一个按钮,当点击它时,会将用户带到地图视图。但是,每次我点击它时,应用程序都会崩溃。
我在4.1.1
上从我的GS3运行它map_screen.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
MapScreenActivity.java
package com.example.poopify;
import android.app.Activity;
import android.os.Bundle;
public class MapScreenActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_screen);
}
}
然后我的manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.poopify"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="14" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.example.poopify.permission.MAPS_RECEIVE"/>
<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" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBUIxDObzLKAfFrg04tPc78LBU1zkzZi6w" />
<activity
android:name="com.example.poopify.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>
<activity android:name="com.example.poopify.MainScreen" >
</activity>
<activity
android:name="com.example.poopify.MapScreenActivity"
android:label="@string/title_activity_map_screen" >
</activity>
</application>
</manifest>
继承我的logcat,但是想知道该怎么做:
11-03 16:47:41.671: E/AndroidRuntime(18159): FATAL EXCEPTION: main
11-03 16:47:41.671: E/AndroidRuntime(18159): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.poopify/com.example.poopify.MapScreenActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2110)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2135)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.app.ActivityThread.access$700(ActivityThread.java:143)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1241)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.os.Handler.dispatchMessage(Handler.java:99)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.os.Looper.loop(Looper.java:137)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.app.ActivityThread.main(ActivityThread.java:4950)
11-03 16:47:41.671: E/AndroidRuntime(18159): at java.lang.reflect.Method.invokeNative(Native Method)
11-03 16:47:41.671: E/AndroidRuntime(18159): at java.lang.reflect.Method.invoke(Method.java:511)
11-03 16:47:41.671: E/AndroidRuntime(18159): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
11-03 16:47:41.671: E/AndroidRuntime(18159): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
11-03 16:47:41.671: E/AndroidRuntime(18159): at dalvik.system.NativeStart.main(Native Method)
11-03 16:47:41.671: E/AndroidRuntime(18159): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
11-03 16:47:41.671: E/AndroidRuntime(18159): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:309)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.app.Activity.setContentView(Activity.java:1914)
11-03 16:47:41.671: E/AndroidRuntime(18159): at com.example.poopify.MapScreenActivity.onCreate(MapScreenActivity.java:13)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.app.Activity.performCreate(Activity.java:5179)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1094)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2074)
11-03 16:47:41.671: E/AndroidRuntime(18159): ... 11 more
11-03 16:47:41.671: E/AndroidRuntime(18159): 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-03 16:47:41.671: E/AndroidRuntime(18159): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
11-03 16:47:41.671: E/AndroidRuntime(18159): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
11-03 16:47:41.671: E/AndroidRuntime(18159): at com.google.android.gms.maps.internal.q.v(Unknown Source)
11-03 16:47:41.671: E/AndroidRuntime(18159): at com.google.android.gms.maps.internal.q.u(Unknown Source)
11-03 16:47:41.671: E/AndroidRuntime(18159): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
11-03 16:47:41.671: E/AndroidRuntime(18159): at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
11-03 16:47:41.671: E/AndroidRuntime(18159): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
11-03 16:47:41.671: E/AndroidRuntime(18159): at com.google.android.gms.dynamic.a.a(Unknown Source)
11-03 16:47:41.671: E/AndroidRuntime(18159): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
11-03 16:47:41.671: E/AndroidRuntime(18159): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.app.Activity.onCreateView(Activity.java:4829)
11-03 16:47:41.671: E/AndroidRuntime(18159): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
答案 0 :(得分:2)
它对我也很有用..你所要做的就是在下面有两个元数据标签链接:
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="yourGoogleAPIKeyHere" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
答案 1 :(得分:1)
如果您确实阅读了该错误,您会发现自己遗失了一些错误。
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" />
使用Google Play服务4.0,您需要声明您的清单中有哪些版本的Google Play服务。
所以这不是一个错误
答案 2 :(得分:1)
在...我...
它应该是一行,如:
<meta-data android:value="XXX" android:name="com.google.android.gms.version"/>
但我们得到:
<meta-data
android:name="com.google.android.maps.v2.API_KEY
android:value="API_KEY
我认为您可以使用此“Applicatin”标签添加此选项,而不仅仅是在xml上编辑
答案 3 :(得分:0)
我的更新后遇到了同样的问题。我找不到崩溃的来源,在阅读了log cat out之后我只想添加这一行:
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
这就像一个魅力。
希望有一天会有所帮助;)