gpt4 book ai didi

android - 在 Android 的对话框中加载 webview 时获取 void android.webkit.WebView.loadUrl?

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

我收到此错误 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代码,我在下面使用过。请提供您的知识来解决它。

02-06 18:07:41.605: E/AndroidRuntime(1492): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.tanas.activities/com.tanas.activities.ContactInfoActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.webkit.WebView.loadUrl(java.lang.String)' on a null object reference 02-06 18:07:41.605: E/AndroidRuntime(1492): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298) 02-06 18:07:41.605: E/AndroidRuntime(1492): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 02-06 18:07:41.605: E/AndroidRuntime(1492): at android.app.ActivityThread.access$800(ActivityThread.java:144) 02-06 18:07:41.605: E/AndroidRuntime(1492): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 02-06 18:07:41.605: E/AndroidRuntime(1492): at android.os.Handler.dispatchMessage(Handler.java:102) 02-06 18:07:41.605: E/AndroidRuntime(1492): at android.os.Looper.loop(Looper.java:135) 02-06 18:07:41.605: E/AndroidRuntime(1492): at android.app.ActivityThread.main(ActivityThread.java:5221) 02-06 18:07:41.605: E/AndroidRuntime(1492): at java.lang.reflect.Method.invoke(Native Method) 02-06 18:07:41.605: E/AndroidRuntime(1492): at java.lang.reflect.Method.invoke(Method.java:372) 02-06 18:07:41.605: E/AndroidRuntime(1492): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 02-06 18:07:41.605: E/AndroidRuntime(1492): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 02-06 18:07:41.605: E/AndroidRuntime(1492): Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.webkit.WebView.loadUrl(java.lang.String)' on a null object reference 02-06 18:07:41.605: E/AndroidRuntime(1492): at com.tanas.activities.ContactInfoActivity.showCustomDialog(ContactInfoActivity.java:37) 02-06 18:07:41.605: E/AndroidRuntime(1492): at com.tanas.activities.ContactInfoActivity.onCreate(ContactInfoActivity.java:21) 02-06 18:07:41.605: E/AndroidRuntime(1492): at android.app.Activity.performCreate(Activity.java:5933) 02-06 18:07:41.605: E/AndroidRuntime(1492): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 02-06 18:07:41.605: E/AndroidRuntime(1492): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251) 02-06 18:07:41.605: E/AndroidRuntime(1492): ... 10 more

代码是

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 小部件。

如果 R.id.webview1R.layout.activity_contact 中,调用 m_llMain 上的 findViewById() >,不是 m_dialog

关于android - 在 Android 的对话框中加载 webview 时获取 void android.webkit.WebView.loadUrl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28366792/

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