[英]android.view.InflateException: Binary XML file line #12: Error inflating class fragment
I want to display Google map in android application. 我想在Android应用程序中显示Google地图。 I have done following steps.
我已经完成以下步骤。
Linked 'google-play-services_lib' to my current project 将“ google-play-services_lib”链接到我当前的项目
(Project properties -> Android -> Add(Into Library Section) -> Selected 'google-play-services_lib'-> Apply -> Ok (项目属性-> Android->添加(进入库部分)->选定的“ google-play-services_lib”->应用->确定
Registered SHA-1 fingerprint with following command 使用以下命令注册SHA-1指纹
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
Generated Android API key from Google API console 从Google API控制台生成的Android API密钥
Modified AndroidManifest.xml as below 修改如下的AndroidManifest.xml
<?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>
Modified activity_main.xml as below 修改后的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" 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"/>
Modified MainActivity.java as below 修改MainActivity.java如下
package com.gaurav.googlemap; 打包com.gaurav.googlemap;
import android.app.Activity; 导入android.app.Activity;
import android.os.Bundle; 导入android.os.Bundle;
import android.view.Menu; 导入android.view.Menu;
import android.view.MenuItem; 导入android.view.MenuItem;
import android.support.v4.app.Fragment; 导入android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity; 导入android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity { 公共类MainActivity扩展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); }
} }
And finally I ran project into Android emulator 最后我将项目运行到Android模拟器中
But there is a exception in LogCat as below 但是LogCat中有一个例外,如下所示
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
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)
我的操作系统是Windows 8.1(32位)
I have heard there is a different way to setup emulator to display Google map. 我听说有另一种方法来设置模拟器以显示Google地图。 Is this related to my problem?
这和我的问题有关吗?
Please help me to fix this problem. 请帮助我解决此问题。 Thanks.
谢谢。
Add this in AndroidManifest.xml 在AndroidManifest.xml中添加它
<meta-data android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.