问题描述
我收到此错误导致:java.lang.NullPointerException:尝试在Android中的对话框中加载Webview时尝试调用虚拟方法void android.webkit.WebView.loadUrl。我附加了日志和代码和我以下使用。请务必提供您的知识解决。
I am getting this error Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.webkit.WebView.loadUrl when I try to load a webview inside a dialog in android.I have attached the log and code and I have used below. Kindly provide your knowledge to solve it.
代码是
m_dialog = new Dialog(ContactInfoActivity.this, R.style.Dialog_No_Border);
m_dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
LayoutInflater m_inflater = LayoutInflater.from(ContactInfoActivity.this);
View m_view = m_inflater.inflate(R.layout.activity_contact, null);
m_llMain = (LinearLayout) m_view.findViewById(R.id.cadllMain);
m_llMain.setBackgroundResource(R.drawable.btn_style_roundcorner);
WebView wv = (WebView) m_dialog.findViewById(R.id.webview1);
//WebView wv = new WebView(this);
wv.loadUrl("http:\\www.google.com");
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
});
m_dialog.setContentView(m_view);
m_dialog.show();
推荐答案
m_dialog
没有一个 R.id.webview1
小部件,显然。
m_dialog
does not have a R.id.webview1
widget, apparently.
如果 R.id.webview1
在 R.layout.activity_contact
中,调用 findViewById()
在 m_llMain
,而不是 m_dialog
。
If R.id.webview1
is in R.layout.activity_contact
, call findViewById()
on m_llMain
, not m_dialog
.
这篇关于在Android中的对话框中加载webview时,会使android.webkit.WebView.loadUrl无效吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!