Skip to content Skip to sidebar Skip to footer

Null Pointer Exception In The Webview

I am getting a null pointer exception in the line where setJavaScriptEnabled(true) is set true. I did not get the exception when I implemented the same program as the only activity

Solution 1:

You might have set a wrong layout here..

setContentView(R.layout.main); // < ------ You might have set a wrong layout here.

Make sure that your WebView is main.xml.

Solution 2:

Try debugging:

if (mWebView == null) { System.out.print("mWebView is null"); }
elseif (mWebView.getSettings() == null) { System.out.print("Settings is null"); }

Probably

findViewById(R.id.webview)

does not return a WebView as you expect.

Post a Comment for "Null Pointer Exception In The Webview"