0

我不明白为什么我无法启动地图?

将项目作为库“google-play-services_lib”挂钩。在模拟器应用程序加载。但我看不到地图。现在得到这个错误。

java.lang.RuntimeException: Unable to start activity ComponentInfo{de.ai.mi.maptrack/de.ai.mi.maptrack.activities.TravelMapActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment

Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment

Caused by: java.lang.ClassCastException: com.google.android.gms.maps.SupportMapFragment cannot be cast to android.app.Fragment

我认为问题是“AndroidManifest”设置错误,但不明白出了什么问题,告诉我。

也许问题不在类和注册“AndroidManifest”的正确位置?

在 Google 控制台中生成此包的​​密钥。

MY_KEY;de.ai.mi.maptrack

我所做的一切都是这样的。 https://developers.google.com/maps/documentation/android/start

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="de.ai.mi.maptrack"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <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-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <permission
        android:name="de.ai.mi.maptrack.activities.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />

    <uses-permission android:name="de.ai.mi.maptrack.activities.permission.MAPS_RECEIVE" />

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="MY_KEY_FROM_GOOGLE_CONSOLE" />

        <activity
            android:name=".activities.StartMenuActivity"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name=".activities.TravelDescriptionActivity" >
        </activity>
        <activity android:name=".activities.TravelMapActivity" >
        </activity>

    </application>

</manifest>

travel_map_activity.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"
    class="com.google.android.gms.maps.SupportMapFragment" />

旅游地图活动

package de.ai.mi.maptrack.activities;

import android.app.Activity;
import android.os.Bundle;
import de.ai.mi.maptrack.R;

public class TravelMapActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.travel_map_activity);
    }
}

谢谢

4

1 回答 1

0

您需要扩展 fragmentactivity 而不是活动。

public class TravelMapActivity  extends android.support.v4.app.FragmentActivity {
于 2013-01-31T13:46:19.160 回答