gpt4 book ai didi

java - Android Google Map API v2 - 膨胀类 fragment 时出错 android.view.InflateException

转载 作者:行者123 更新时间:2023-12-01 11:58:03 24 4
gpt4 key购买 nike

我按照 Google Maps Android API v2 文档在我的应用程序中使用 map 。我收到错误“”我已经尝试了所有方法,但仍然无法解决它。

这是我的MainActivity.java

package com.example.maps;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends FragmentActivity {

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

这是xml布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}" >

<TextView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/header"
/>

</RelativeLayout>

这是我在 logcat 中遇到的错误

02-02 16:02:46.110: E/AndroidRuntime(11094): FATAL EXCEPTION: main
02-02 16:02:46.110: E/AndroidRuntime(11094): Process: com.example.maps, PID: 11094
02-02 16:02:46.110: E/AndroidRuntime(11094): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.maps/com.example.maps.MainActivity}: android.view.InflateException: Binary XML file line #22: Error inflating class fragment

Manifest.xml

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

<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="19" />
<permission
android:name="com.example.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature"
></permission>
<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"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/gyan_logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >


<activity
android:name="com.example.maps.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>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:name="com.google.android.gms.maps.MapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBJ4S3tVGq4GWjgsuJ2zm0EAfUPN3yFKKA"/>
</application>

</manifest>

请帮我解决此错误。

最佳答案

你应该改变

  android:name="com.google.android.gms.maps.MapFragment"

  android:name="com.google.android.gms.maps.SupportMapFragment"

因为您正在使用FragmentActivity

编辑:

您还需要添加 manifest.xml

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

关于java - Android Google Map API v2 - 膨胀类 fragment 时出错 android.view.InflateException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28276051/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com