我得到这个错误产生的原因:显示java.lang.NullPointerException:试图调用虚拟方法无效android.webkit.WebView.loadUrl当我尝试加载android.I对话框内的WebView已附上日志和代码,我下面使用了。 请提供您解决这个问题的知识。
02-06 18:07:41.605:E / AndroidRuntime(1492):了java.lang.RuntimeException:无法启动活动ComponentInfo {com.tanas.activities / com.tanas.activities.ContactInfoActivity}:显示java.lang.NullPointerException:尝试调用虚拟方法 '无效android.webkit.WebView.loadUrl(java.lang.String中)' 上的空对象引用02-06 18:07:41.605:E / AndroidRuntime(1492):在android.app.ActivityThread.performLaunchActivity (ActivityThread.java:2298)02-06 18:07:41.605:E / AndroidRuntime(1492):在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)02-06 18:07:41.605:E / AndroidRuntime (1492):在android.app.ActivityThread.access $ 800(ActivityThread.java:144)02-06 18:07:41.605:E / AndroidRuntime(1492):在android.app.ActivityThread $ H.handleMessage(ActivityThread.java :1278)02-06 18:07:41.605:E / AndroidRuntime(1492):在android.os.Handler.dispatchMessage(Handler.java:102)02-06 18:07:41.605:E / AndroidRuntime(1492):在android.os.Looper.loop(Looper.java:135)02-06 18:07:41.605:电子 / AndroidRuntime(1492):在android.app.ActivityThread.main(ActivityThread.java:5221)02-06 18:07:41.605:E / AndroidRuntime(1492):在java.lang.reflect.Method.invoke(本地方法)02-06 18:07:41.605:E / AndroidRuntime(1492):在java.lang.reflect.Method.invoke(Method.java:372)02-06 18:07:41.605:E / AndroidRuntime(1492):在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:899)02-06 18:07:41.605:E / AndroidRuntime(1492):在com.android.internal.os.ZygoteInit.main( ZygoteInit.java:694)02-06 18:07:41.605:E / AndroidRuntime(1492):显示java.lang.NullPointerException:致尝试调用虚拟方法“无效android.webkit.WebView.loadUrl(java.lang中。上的空对象引用字符串)” 02-06 18:07:41.605:E / AndroidRuntime(1492):在com.tanas.activities.ContactInfoActivity.showCustomDialog(ContactInfoActivity.java:37)02-06 18:07:41.605: E / AndroidRuntime(1492):在com.tanas.activities.ContactInfoActivity.onCreate(ContactInfoActivity.java:21)02-06 18:07:41.605:E / Androi dRuntime(1492):在android.app.Activity.performCreate(Activity.java:5933)02-06 18:07:41.605:E / AndroidRuntime(1492):在android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105 )02-06 18:07:41.605:E / AndroidRuntime(1492):在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)02-06 18:07:41.605:E / AndroidRuntime(1492):.. 10更多
码是
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();