1

因此,我在主屏幕上有一个按钮,单击该按钮会将用户带到地图视图。但是,每次我单击它时,应用程序都会崩溃。

我在 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)
4

4 回答 4

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" />
于 2013-12-15T07:38:22.553 回答
1

如果您真的阅读了错误,您会发现您的 minifest 中缺少某些内容。

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 services 4.0,您需要在清单中声明您拥有的 google play services 版本。

所以这不是一个错误

于 2013-11-04T00:33:29.873 回答
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    

我认为您可以使用此“应用程序”选项卡来添加此选项卡,而不仅仅是在 xml 上进行编辑

于 2013-11-21T14:02:59.180 回答
0

我更新后遇到了同样的问题。我找不到崩溃的来源,在阅读了 log cat 之后,我只添加了这一行:

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

这就像一个魅力。

希望有一天会有所帮助;)

于 2013-11-26T14:02:19.393 回答