[英]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))).getMap();
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.