错误:MapFragment无法转换为android.support.v4.app.Fragment

首先,我看到这里: 从活动开始FragmentActivity ,现在我有以下问题:

MapsActivity:

public class MapsActivity extends FragmentActivity { private GoogleMap mMap; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.maps); setUpMapIfNeeded(); } ... 

并希望通过以下方式从MainActivity中启动它:

 startActivity(new Intent(this, MapsActivity.class)); 

该活动已在Android Manifest中注册:

 <activity android:name="de.xbjoernx.gapp.MapsActivity"></activity> 

错误

 FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{de.xbjoernx.gapp/de.xbjoernx.gapp.MapsActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2358) at android.app.ActivityThread.access$600(ActivityThread.java:153) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1247) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:5227) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562) at dalvik.system.NativeStart.main(Native Method) Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) at android.view.LayoutInflater.inflate(LayoutInflater.java:466) at android.view.LayoutInflater.inflate(LayoutInflater.java:396) at android.view.LayoutInflater.inflate(LayoutInflater.java:352) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:323) at android.app.Activity.setContentView(Activity.java:1881) at de.xbjoernx.gapp.MapsActivity.onCreate(MapsActivity.java:19) at android.app.Activity.performCreate(Activity.java:5104) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2262) ... 11 more Caused by: java.lang.ClassCastException: com.google.android.gms.maps.MapFragment cannot be cast to android.support.v4.app.Fragment at android.support.v4.app.Fragment.instantiate(Fragment.java:394) at android.support.v4.app.Fragment.instantiate(Fragment.java:369) at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676) ... 20 more 

任何build议如何解决它?

非常感谢:)

因为您正在扩展FragmentActivity ,这表明您正在使用与较低版本的Android兼容的Support library v4。 用你的xml文件里的SupportMapFragmentreplaceMapFragmentSupportMapFragment是与Android支持包一起使用的。 MapFragment适用于本地API Level 11版本的片段。