简体   繁体   English

android.view.InflateException:二进制XML文件第12行:膨胀类片段的错误

[英]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. 我已经完成以下步骤。

  1. Created a new android application project with the package name com.gaurav.googlemap 使用包名称com.gaurav.googlemap创建了一个新的android应用程序项目
  2. Downloaded Google Play Services SDK from SDK Manager 从SDK Manager下载了Google Play服务SDK
  3. Imported 'google-play-services_lib' into current workspace 将“ google-play-services_lib”导入当前工作区
  4. 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”->应用->确定

  5. 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

  6. Generated Android API key from Google API console 从Google API控制台生成的Android API密钥

  7. 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> 

  8. 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"/> 

  9. 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); } 

    } }

  10. 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.

相关问题 android.view.InflateException:二进制XML文件第12行:二进制XML文件第12行:夸大类片段的错误 - android.view.InflateException: Binary XML file line #12: Binary XML file line #12: Error inflating class fragment android.view.InflateException:二进制XML文件第0行:二进制XML文件第0行:膨胀类片段时出错 - android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment android.view.InflateException:二进制XML文件第7行:二进制XML文件第7行:夸大类片段的错误 - android.view.InflateException: Binary XML file line #7: Binary XML file line #7: Error inflating class fragment 无法启动活动ComponentInfo {Activity}:android.view.InflateException:二进制XML文件行#12:错误膨胀类片段 - Unable to start activity ComponentInfo{Activity}: android.view.InflateException: Binary XML file line #12: Error inflating class fragment Android调试错误android.view.InflateException:二进制XML文件第9行:夸大类片段的错误 - Android debugging error android.view.InflateException: Binary XML file line #9: Error inflating class fragment Android-android.view.InflateException:二进制XML文件第9行:膨胀类片段的错误 - Android - android.view.InflateException: Binary XML file line #9: Error inflating class fragment android.view.InflateException:二进制XML文件行#8:错误膨胀类片段 - android.view.InflateException: Binary XML file line #8: Error inflating class fragment 无法膨胀android.view.InflateException:二进制XML文件第24行:膨胀类片段时出错 - Failed to inflate android.view.InflateException: Binary XML file line #24: Error inflating class fragment android.view.InflateException:二进制XML文件第91行:错误放大了类片段 - android.view.InflateException: Binary XML file line #91: Error inflating class fragment RuntimeException:android.view.InflateException:二进制XML文件第8行:夸大类片段的错误 - RuntimeException : android.view.InflateException: Binary XML file line #8: Error inflating class fragment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM