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>
- Kotlin,Java,multidex,Dagger 2,Butterknife和Realm:transformClassesWithMargingForDebug:重复条目:org / jetbrains / annotations / NotNull.class
- 如何使用Intent Anko的调用包装?
- 蓝牙客户端Socket每次得到相同的异常
- 用kotlin设置领域时出错
- 布局位于库模块中时合成视图的未解决的参考
- 在子模块中的Android数据绑定
- 如何使圆角的ImageView?
- 仅在AppBarLayout完全展开时启用SwipeRefreshLayout
- 如何将数组列表中的特定项目移动到第一项