android.view.InflateException:二进制XML文件第12行:膨胀类片段的错误 [英] android.view.InflateException: Binary XML file line #12: Error inflating class fragment

查看:57
本文介绍了android.view.InflateException:二进制XML文件第12行:膨胀类片段的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android应用程序中显示Google地图.我已经完成了以下步骤.

I want to display Google map in android application. I have done following steps.

  1. 使用包名称com.gaurav.googlemap创建了一个新的android应用程序项目
  2. 从SDK Manager下载了Google Play服务SDK
  3. 将"google-play-services_lib"导入当前工作区
  4. 将"google-play-services_lib"链接到我当前的项目

  1. Created a new android application project with the package name com.gaurav.googlemap
  2. Downloaded Google Play Services SDK from SDK Manager
  3. Imported 'google-play-services_lib' into current workspace
  4. Linked 'google-play-services_lib' to my current project

(项目属性-> Android->添加(进入库部分)->选定的"google-play-services_lib"->应用->确定

(Project properties -> Android -> Add(Into Library Section) -> Selected 'google-play-services_lib'-> Apply -> Ok

使用以下命令注册SHA-1指纹

Registered SHA-1 fingerprint with following command

keytool -list -v -keystore%USERPROFILE%.android \ debug.keystore" -alias androiddebugkey -storepass android -keypass android

keytool -list -v -keystore "%USERPROFILE%.android\debug.keystore" -alias androiddebugkey -storepass android -keypass android

从Google API控制台生成的Android API密钥

Generated Android API key from Google API console

如下所示修改了AndroidManifest.xml

Modified AndroidManifest.xml as below

<?xml version="1.0" encoding="utf-8"?>

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

<permission 
    android:name="com.gaurav.googlemap.permission.MAPS_RECEIVE"
    android:protectionLevel="signature"></permission>
<uses-permission 
    android:name="com.gaurav.googlemap.permission.MAPS_RECEIVE"/>
<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"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<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="AIzaSyC3hd_PcjjfraFGfnx3UVi0FLO5AwgxFT8" />
    <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>
</application>

修改的activity_main.xml如下

Modified activity_main.xml as below

<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.gaurav.googlemap.MainActivity" >


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

如下所示修改了MainActivity.java

Modified MainActivity.java as below

package com.gaurav.googlemap;

package com.gaurav.googlemap;

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

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

公共类MainActivity扩展了FragmentActivity {

public class MainActivity extends FragmentActivity {

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

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}

}

最后我将项目运行到Android模拟器中

And finally I ran project into Android emulator

但是LogCat中有一个异常,如下所示

But there is a exception in LogCat as below

02-14 16:41:46.947: E/AndroidRuntime(1260): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.gaurav.googlemap/com.gaurav.googlemap.MainActivity}: android.view.InflateException: Binary XML file line #12: Error inflating class fragment

我已经阅读了许多有关类似问题的答案,但没有得到此问题的解决方法.我的操作系统是Windows 8.1(32位)

I have read many answers on similar questions, but I didn't get this problem fix. I am having operating system Windows 8.1 (32-bit)

我听说有一种设置模拟器以显示Google地图的方法.这与我的问题有关吗?

I have heard there is a different way to setup emulator to display Google map. Is this related to my problem?

请帮助我解决此问题.谢谢.

Please help me to fix this problem. Thanks.

推荐答案

将其添加到AndroidManifest.xml

Add this in AndroidManifest.xml

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

这篇关于android.view.InflateException:二进制XML文件第12行:膨胀类片段的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆