gpt4 book ai didi

android - kotlin webview android.view.View android.view.View.findViewById(int)' on a null object reference ko

转载 作者:行者123 更新时间:2023-11-29 18:29:56 25 4
gpt4 key购买 nike

我遇到了这个错误,有人知道如何解决吗?欢迎任何帮助。谢谢。我正在使用 fragment

class ForumFragment : Fragment() {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {



ERROR LINE-> val wv = webView.findViewById(R.id.webView) as WebView

webView.loadUrl("https://www.google.com/");
webView.clearView();
webView.measure(100, 100);
webView.getSettings().setUseWideViewPort(true)
webView.getSettings().setLoadWithOverviewMode(true);

return inflater.inflate(R.layout.fragment_forum, container, false)
}

}

LOGCAT 错误 ->

java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.View.findViewById(int)' on a null object reference
at .fragments.ForumFragment.onCreateView(ForumFragment.kt:45

最佳答案

class ForumFragment : Fragment() {

private lateinit var v: View
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
v = inflater.inflate(R.layout.frag_list_project, container, false)
val wv = v.findViewById(R.id.webView) as WebView

wv.loadUrl("https://www.google.com/");
wv.clearView();
wv.measure(100, 100);
wv.getSettings().setUseWideViewPort(true)
wv.getSettings().setLoadWithOverviewMode(true);
return v

}

关于android - kotlin webview android.view.View android.view.View.findViewById(int)' on a null object reference ko,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56822727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com