Java 无法将android.app.Fragment强制转换为mapping.SupportMapFragment

Java 无法将android.app.Fragment强制转换为mapping.SupportMapFragment,java,android,here-api,Java,Android,Here Api,我从这里添加了这个行标记map doc,它没有编译 mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.supportmapfragmentj); 我越来越 无法将android.app.Fragment强制转换为com.here.android.mpa.mapping.SupportMapFragment 知道我的片段xml如下 <?xml version="1.0" encodin

我从这里添加了这个行标记map doc,它没有编译

mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.supportmapfragmentj);
我越来越

无法将android.app.Fragment强制转换为com.here.android.mpa.mapping.SupportMapFragment

知道我的片段xml如下

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapGuiTestActivityJ">

<fragment
        class="com.here.android.mpa.mapping.SupportMapFragment"
        android:id="@+id/supportmapfragmentj"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</android.support.constraint.ConstraintLayout>

试试这个:

mapFragment = (SupportMapFragment) rootView.findViewById(R.id.supportmapfragmentj);

其中,
rootView
是视图容器,您可以在
onCreateView()中返回它。
使用“支持片段管理器”可能会解决此问题

尝试更换

mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.supportmapfragmentj);
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.supportmapfragmentj);

mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.supportmapfragmentj);
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.supportmapfragmentj);