我是學習Android的初學者,請幫助我解決這個問題。 我不斷收到此錯誤:Android WebView錯誤
02-19 16:55:00.330: E/AndroidRuntime(2335): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mkyong.android/com.mkyong.android.WebViewActivity}: java.lang.NullPointerException
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
WebView mywebview = (WebView) findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
WebSettings webSettings = mywebview.getSettings();
mywebview.loadUrl("http://www.google.com");
}
我的XML文件:
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
您的WebView實例可能爲null。編輯你的問題並在那裏發佈你的'webview.xml'佈局文件內容。 – FoamyGuy 2013-02-19 16:49:10
你可以發佈你的XML嗎?空指針異常意味着你指的是不存在的東西。此外,logcat會發布哪一行導致錯誤,發佈特定行也非常有幫助 – sam 2013-02-19 16:49:16
@Ali嘗試清理和重建您的項目。在這一點上,您的代碼似乎沒有任何錯誤。 – 2013-02-19 16:53:26