Java 执行以下代码后,GoogleMap对象返回null
以下是布局的XML文件:Java 执行以下代码后,GoogleMap对象返回null,java,android,Java,Android,以下是布局的XML文件: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <fragment andr
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
我甚至用“MapFragment”而不是“SupportMapFragment”来尝试它,但没有出现同样的错误
我已经研究了好几天了。有人能帮我吗。根据,在调用
SupportMapFragment
的onCreateView()
后,GoogleMap
对象将变得可用,因此更好的方法是在活动中调用getMap()
。现在有超过97%的设备运行Android 2.3(姜饼)或更高的平台版本,我们将从这次发布的Google Play services SDK中放弃对Froyo的支持,以便将来能够提供更强大的API。这意味着您将无法在运行Android2.2(Froyo)的设备上使用这些新API。GoogleMap是GooglePlay服务的一部分。所以请将您的MinSDK更改为api级别10,然后重试
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.maptest2"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.example.maptest2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.maptest2.permission.MAPS_RECEIVE" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<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" >
<activity
android:name="com.example.maptest2.MapTest2"
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="MyKey" />
<meta-data android:name="com.google.android.gms.version" android:value="4030500" />
</application>
</manifest>
SupportMapFragment mapFrag = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
googleMap = mapFrag.getMap();