简体   繁体   English

Java Android模拟器:使用Maps v2时发生崩溃(由android.view.InflateException引起:二进制XML文件第11行:错误夸大了类片段

[英]Java Android Emulator: Crash when using Maps v2 (Caused by android.view.InflateException: Binary XML file line #11: Error Inflating class fragment

I am trying to show Google Maps on my application but it always crash. 我试图在我的应用程序上显示Google Maps,但是它总是崩溃。 I have gotten the API from Google and already added the Google Play Service library to my project. 我已经从Google获得了API,并且已经将Google Play服务库添加到了我的项目中。 The Map is called in DisplayResult.java Map在DisplayResult.java中调用

Here is my AndroidManifest.xml: 这是我的AndroidManifest.xml:

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

<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="19" />

<permission
    android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>

<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="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<uses-permission android:name="com.example.newmapview.permission.MAPS_RECEIVE" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.chicagobus.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>
    <activity
        android:name="com.example.chicagobus.DisplayMessageActivity"
        android:label="@string/title_activity_display_message"
        android:parentActivityName="com.example.chicagobus.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.chicagobus.MainActivity" />
    </activity>
    <activity
        android:name="com.example.chicagobus.DisplayResultActivity"
        android:label="@string/title_activity_display_result"
        android:parentActivityName="com.example.chicagobus.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.example.chicagobus.MainActivity" />
    </activity>
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyB8J8kUL9n..................." />
    <meta-data android:name="com.google.android.gms.version"
         android:value="@integer/google_play_services_version" />
</application>

And this is the layout of DisplayResult.java that calls the map: 这是调用地图的DisplayResult.java的布局:

<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=".DisplayResultActivity" >

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

</RelativeLayout>

And here is my Java code: 这是我的Java代码:

package com.example.chicagobus;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class DisplayResultActivity extends FragmentActivity {

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

Any ideas about this? 有什么想法吗?

Change this: 更改此:

<permission
    android:name="com.vogella.android.locationapi.maps.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
// and
<uses-permission android:name="com.example.newmapview.permission.MAPS_RECEIVE" />

By the package name of your app as: 应用程序的软件包名称为:

<permission
    android:name="com.example.chicagobus.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />
// and
<uses-permission android:name="com.example.chicagobus.permission.MAPS_RECEIVE" />  

Also, try to add this code to your onCreate method to initialize your fragment map: 另外,尝试将以下代码添加到onCreate方法中以初始化片段映射:

myMap = ((SupportMapFragment) (getSupportFragmentManager().findFragmentById(R.id.map))).g‌​etMap();

Finally, as @mohammedmomn said: you cannot use Google Play Services on an emulator... I mean not always. 最后,正如@mohammedmomn所说:您不能在模拟器上使用Google Play Services ...我的意思不是总是如此。 To use it, see these tips: 要使用它,请参阅以下提示:
1. Running google map application on Android Emulator 1. 在Android模拟器上运行Google Map应用程序
2. How to Run Google Map API V2 on Android Emulator . 2. 如何在Android模拟器上运行Google Map API V2
And this question might help you: Running Google Maps v2 on Android Emulator 这个问题可能会对您有所帮助: 在Android模拟器上运行Google Maps v2

Let me know if that helps you. 让我知道这是否对您有帮助。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 原因:android.view.InflateException:二进制XML文件行#13:错误夸大了类片段 - Caused by: android.view.InflateException: Binary XML file line #13: Error inflating class fragment 我有“android.view.InflateException:二进制 XML 文件第 11 行:二进制 XML 文件第 11 行:膨胀 class 片段时出错” - I have “android.view.InflateException: Binary XML file line #11: Binary XML file line #11: 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 引起:android.view.InflateException:二进制 XML 文件第 11 行:错误膨胀类 io.flutter.view.FlutterView - Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class io.flutter.view.FlutterView 原因:android.view.InflateException:二进制XML文件第9行:错误膨胀了类android.widget.ImageView - Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class android.widget.ImageView 如何修复android.view.InflateException:使用Google Maps v2片段时,错误放大类片段 - How to fix the android.view.InflateException: Error inflating class fragment when using google maps v2 fragment 谷歌地图视图android.view.InflateException:二进制XML文件-错误夸大类片段 - Google maps view android.view.InflateException: Binary XML File - 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.view.InflateException:二进制XML文件第2行:膨胀类错误<unknown> - Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM