无法将 android.app.Fragment 转换为 mapping.SupportMapFragment
cannot cast android.app.Fragment to mapping.SupportMapFragment
我从这里的地图文档中添加了这个行标记,它没有编译
mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.supportmapfragmentj);
我得到
cannot cast android.app.Fragment to 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
是视图容器,您 return 在 onCreateView()
也许使用 'Support Fragment Manager' 可以解决这个问题
尝试替换
mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.supportmapfragmentj);
和
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.supportmapfragmentj);
我从这里的地图文档中添加了这个行标记,它没有编译
mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.supportmapfragmentj);
我得到
cannot cast android.app.Fragment to 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
是视图容器,您 return 在 onCreateView()
也许使用 'Support Fragment Manager' 可以解决这个问题
尝试替换
mapFragment = (SupportMapFragment) getFragmentManager().findFragmentById(R.id.supportmapfragmentj);
和
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.supportmapfragmentj);