Kotlin webview崩溃

我想从一个Fragment访问一个WebView和kotlin不停地说:

 kotlin.TypeCastException: null cannot be cast to non-null type android.webkit.WebView 

我试图使其为默认,然后初始化它,但也不起作用。 任何建议,我怎样才能使其工作?

我的代码:

 private lateinit var webView: WebView override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? { val view = inflater!!.inflate(R.layout.editor_edit_fragment, container, false) webView = view.findViewById(R.id.webview) as WebView resumeWebView() return view } 

XML:

 <?xml version="1.0" encoding="utf-8"?> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <WebView android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/webview" /> </LinearLayout>