Android 从片段到SupportMapFragment的不可转换类型错误

Android 从片段到SupportMapFragment的不可转换类型错误,android,android-fragments,Android,Android Fragments,所以我有一个片段类: public class MyMapFragmentActivity extends Fragment implements LocationListener, GoogleMap.OnMapClickListener, GoogleMap.OnMapLongClickListener { 其中我定义了一个SupportMapFragment: private SupportMapFragment fragment; 我正在尝试使用findFragmen

所以我有一个片段类:

public class MyMapFragmentActivity extends Fragment implements LocationListener,
        GoogleMap.OnMapClickListener, GoogleMap.OnMapLongClickListener {
其中我定义了一个SupportMapFragment:

private SupportMapFragment fragment;
我正在尝试使用findFragmentById:

    @Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    FragmentManager fm = getChildFragmentManager();
    fragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
    if (fragment == null) {
        fragment = SupportMapFragment.newInstance();
        fm.beginTransaction().replace(R.id.content_frame, fragment).commit();
    }
}
线路

fragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
尽管“fragment”是SupportMapFragment,但这会导致不可逆的类型错误: 无法将android.app.fragment强制转换为com.google.android.gms.maps.SupportMapFragment

我正在使用片段布局:

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.SupportMapFragment" />


您正在混合支持片段和非支持片段管理器。请改用SupportFragmentManager。

如果您使用兼容库,请使用
getSupportFragmentManager().findFragmentById(R.id.fragment)
以其他方式从
android.app.Fragment
扩展而不是
android.support.v4.app.Fragment

我在任何开发文档中都没有看到“SupportFragmentManager”,并且它没有出现在代码提示中?它在android支持库中。它是将片段(和其他一些东西)回传到2.x的代码。或者,您可以使用MapFragment而不是SupportMapFragment,但这将破坏您在2.x上的应用程序。基本上,要在2.x上工作,只需使用支持类。要仅使用4.0+版本,可以使用普通版本。但千万不要把两者混为一谈。你能在谷歌网站上找到支持它们的参考资料吗?我看不见它;这个答案有70分,这就是我尝试的方式:只需谷歌搜索你指定的例外。其原因是支撑物和非支撑物碎片的混合。这两者不能混为一谈。