Android Can';无法让SupportMapFragment返回任何内容..似乎始终为空
这是我的代码: 事情的关键是,onMapReady没有被调用,所以我就和 错误Android Can';无法让SupportMapFragment返回任何内容..似乎始终为空,android,google-maps,kotlin,supportmapfragment,Android,Google Maps,Kotlin,Supportmapfragment,这是我的代码: 事情的关键是,onMapReady没有被调用,所以我就和 错误 var mapFragment = activity.supportFragmentManager.findFragmentById(R.id.mapF) as SupportMapFragment 进程:com.example.herbstzu.listview,PID:16963 kotlin.TypeCastException:null不能转换为非null类型 com.google.android.g
var mapFragment = activity.supportFragmentManager.findFragmentById(R.id.mapF) as SupportMapFragment
进程:com.example.herbstzu.listview,PID:16963
kotlin.TypeCastException:null不能转换为非null类型
com.google.android.gms.maps.SupportMapFragment
XML
.....
<LinearLayout
android:id="@+id/LayoutInfo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginVertical="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/imagePhone2"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="start"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
app:srcCompat="@drawable/ic_exclamation" />
<TextView
android:id="@+id/info_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="TextView"
android:textColor="#000000" />
</LinearLayout>
<fragment
class="com.google.android.gms.maps.MapFragment"
android:id="@+id/mapF"
android:layout_width="match_parent"
android:layout_height="200dp"/>
</LinearLayout>
</ScrollView>
您使用了错误的片段管理器。您需要使用supportFragmentManager
var mapFragment = activity.supportFragmentManager.findFragmentById(R.id.mapF) as SupportMapFragment