嗨我在Android中有点新鲜,我正在开发一个显示和映射一些标记的代码。我使用了2个按钮,一个用于查看地图,另一个用于添加信息。问题是,我第一次点击显示地图,它显示,但当我回到“mainmenu”并再次点击显示地图时,只需显示黑屏并显示此错误:
{{2 }}
我正在使用API 16,如果我没有错,我应该使用像我正在做的MapFragmet,而不是扩展Fragment,因为它在旧版本中使用,不是吗?
我的XML:
android.view.inflateException: Binary XML file line #11: Error inflating class fragment
我的清单
<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=".MainActivity" >
<fragment
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
<ImageView
android:id="@+id/logo"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignRight="@+id/map"
android:layout_alignTop="@+id/map"
android:contentDescription="@string/hintlogo"
android:src="@drawable/logo" />
</RelativeLayout>
我的班级名为TudoImoveis:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="uri.br.rs"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="16" />
<!-- Permissão para exibir o mapa -->
<permission
android:name="uri.br.rs.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="uri.br.rs.permission.MAPS_RECEIVE"/>
<!-- Permissão para interner, entre outros -->
<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"/>
<!-- Estas permissões não são necessárias para usar o
Google Maps Android API v2, mas são recomendadas. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<!-- Permissão para usar o OpenGL -->
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:allowBackup="true"
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<!-- Chave do Google Maps Android, registrada no site do Google APIs -->
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="some_key"/>
<activity
android:name="uri.br.rs.TudoImoveis"
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>
</manifest>
答案 0 :(得分:1)
将您的课程扩展到Fragmentactivity
检查是否添加了google play服务以正确构建路径
转到“项目”|“属性” 选择“订购和导出”选项卡中的“Java构建路径”部分,选择googleplay服务 并清理你的项目