- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我收到此错误 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.webview1
在 R.layout.activity_contact
中,调用 m_llMain
上的 findViewById()
>,不是 m_dialog
。
关于android - 在 Android 的对话框中加载 webview 时获取 void android.webkit.WebView.loadUrl?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28366792/
我是一名优秀的程序员,十分优秀!