Java 无法在emulator和设备上加载Android Mapview活动
我正在尝试在模拟器和设备上加载mapview 我已经尝试了两天了,但有一段时间我只是得到了网格线,没有任何地图,有时会出现致命错误,我的应用程序无法在我的模拟器和设备上启动 我尝试了所有的东西,互联网上的每一个代码,但都不起作用。 你是我最后的希望 我遵循上面所述的步骤 我的API密钥是从 我已经尽了我所能。请告诉我,如果这个过程不正确,那么我应该怎么做。我是为姜饼2.3.3 API 10做的 等待答案,谢谢 我的原木猫: 07-06 02:12:45.692:E/AndroidRuntime3020:java.lang.RuntimeException:无法启动活动组件信息{com.example.maps/com.example.maps.MainActivity}:android.view.InflateException:二进制XML文件第2行:膨胀类片段时出错 我的男性节:Java 无法在emulator和设备上加载Android Mapview活动,java,android,xml,Java,Android,Xml,我正在尝试在模拟器和设备上加载mapview 我已经尝试了两天了,但有一段时间我只是得到了网格线,没有任何地图,有时会出现致命错误,我的应用程序无法在我的模拟器和设备上启动 我尝试了所有的东西,互联网上的每一个代码,但都不起作用。 你是我最后的希望 我遵循上面所述的步骤 我的API密钥是从 我已经尽了我所能。请告诉我,如果这个过程不正确,那么我应该怎么做。我是为姜饼2.3.3 API 10做的 等待答案,谢谢 我的原木猫: 07-06 02:12:45.692:E/AndroidRuntime3
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maps"
android:versionCode="1"
android:versionName="1.0" >
<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"/>
<!-- The following two permissions are not required to use
Google Maps Android API v2, but are recommended. -->
<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"/>
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="10" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<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>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AEdPqrEAAAAI5QAuDgiTRjyU-y_MK-ZRQqBaN_VoLb4gADuCwA"/>
</application>
在main.xml中
不应该
android:name=com.google.android.gms.maps.MapFragment
是
class=com.google.android.gms.maps.MapFragment好吧,您正在使用一个片段,但将其加载到MapView中。这就是为什么会出现RuntimeException,因为无法将片段膨胀到MapView对象中。MapView是android maps API版本1中支持的一个旧类,现在已弃用 从您引用的开发人员站点: 注:谷歌地图Android API v2使用了一种新的密钥管理系统。Google Maps Android v1应用程序(通常称为MapView)中的现有密钥不能与v2 API一起使用 您的活动实际上应该扩展MapFragment,您应该使用FragmentManager或SupportFragmentManager来扩展地图
public class MyActivity extends FragmentActivity {
private GoogleMap mMapView;
private SupportMapFragment mFragment;
@Override
protected void onCreate() {
super.onCreate();
FragmentManager fragmentManager = getSupportFragmentManager();
mFragment = ((SupportMapFragment) fragmentManager.findFragmentById(R.id.map));
mMapView = mFragment.getMap();
mMapView.getUiSettings().setZoomControlsEnabled(true);
// configure other settings of map view
}
}
布局xml中的类的名称也应该是SupportMapFragment,如下所示:
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
xmlns:tools="http://schemas.android.com/tools" />
您可以在此处找到更多信息:只是ooi,为什么不使用targetSdk 17?谢谢您的回复,但这不起作用。当我将“name”替换为“class”时它给出的错误=错误:在包“android”中找不到属性“class”的资源标识符。@MuhammadFaraz更新了我的答案,我错误地将名称空间放在了哪一个支持包中,即使在扩展FragmentActivity之后,我也应该下载该支持包,它表明没有任何名为GoogleMap或SupportMapFragments的类,您必须添加support jar。通读指南。它解释得很好,而且很有效:您能告诉我从哪里可以下载这个support.jar吗
public class MyActivity extends FragmentActivity {
private GoogleMap mMapView;
private SupportMapFragment mFragment;
@Override
protected void onCreate() {
super.onCreate();
FragmentManager fragmentManager = getSupportFragmentManager();
mFragment = ((SupportMapFragment) fragmentManager.findFragmentById(R.id.map));
mMapView = mFragment.getMap();
mMapView.getUiSettings().setZoomControlsEnabled(true);
// configure other settings of map view
}
}
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
xmlns:tools="http://schemas.android.com/tools" />