【发布时间】:2018-01-04 11:12:37
【问题描述】:
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:
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方法
标签: android dictionary kotlin