为什么不能显示谷歌地图V2?我的代码:AnroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.daitran.mapversion2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="18" />
<permission
android:name="com.daitran.mapversion2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.daitran.mapversion2.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<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-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.daitran.mapversion2.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="AIzaSyBTLEIcHn7wKQQC_q6y0YcJ7Ffw03PHfHs" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
</application>
</manifest>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
MainActivity.java
package com.daitran.mapversion2;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
我运行并得到一个错误:
11-11 01:06:29.958: E/AndroidRuntime(27914): FATAL EXCEPTION: main
11-11 01:06:29.958: E/AndroidRuntime(27914): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.daitran.mapversion2/com.daitran.mapversion2.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1996)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2023)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.app.ActivityThread.access$600(ActivityThread.java:127)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1174)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.os.Handler.dispatchMessage(Handler.java:99)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.os.Looper.loop(Looper.java:137)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.app.ActivityThread.main(ActivityThread.java:4503)
11-11 01:06:29.958: E/AndroidRuntime(27914): at java.lang.reflect.Method.invokeNative(Native Method)
11-11 01:06:29.958: E/AndroidRuntime(27914): at java.lang.reflect.Method.invoke(Method.java:511)
11-11 01:06:29.958: E/AndroidRuntime(27914): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:809)
11-11 01:06:29.958: E/AndroidRuntime(27914): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:576)
11-11 01:06:29.958: E/AndroidRuntime(27914): at dalvik.system.NativeStart.main(Native Method)
11-11 01:06:29.958: E/AndroidRuntime(27914): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:699)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.view.LayoutInflater.rInflate(LayoutInflater.java:741)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.view.LayoutInflater.inflate(LayoutInflater.java:491)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
11-11 01:06:29.958: E/AndroidRuntime(27914): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:252)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.app.Activity.setContentView(Activity.java:1837)
11-11 01:06:29.958: E/AndroidRuntime(27914): at com.daitran.mapversion2.MainActivity.onCreate(MainActivity.java:11)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.app.Activity.performCreate(Activity.java:4479)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1050)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1960)
11-11 01:06:29.958: E/AndroidRuntime(27914): ... 11 more
11-11 01:06:29.958: E/AndroidRuntime(27914): Caused by: java.lang.ClassCastException: com.google.android.gms.maps.SupportMapFragment cannot be cast to android.app.Fragment
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.app.Fragment.instantiate(Fragment.java:574)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.app.Fragment.instantiate(Fragment.java:549)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.app.Activity.onCreateView(Activity.java:4249)
11-11 01:06:29.958: E/AndroidRuntime(27914): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:675)
11-11 01:06:29.958: E/AndroidRuntime(27914): ... 21 more
你能帮助我吗?谢谢大家。