override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View {
var view: View = inflater?.inflate(R.layout.map_fragment, null)!!
var mapFragment : SupportMapFragment?=null
mapFragment= fragmentManager.findFragmentById(R.id.map) as SupportMapFragment
mapFragment.getMapAsync(this)
return view
}
的logcat:科特林与地图Android中
FATAL EXCEPTION: main
kotlin.TypeCastException: null cannot be cast to non-null type
com.google.android.gms.maps.SupportMapFragment
at example.com.kotlinexamplebydimple.Mapfragment.onCreateView(Mapfragment.kt:36)
在此线路上错误显示:
mapFragment= fragmentManager.findFragmentById(R.id.map) as SupportMapFragment
没有初始化的fragmentManager –
其getFragmentManager方法是直接使用 –