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 in my application, but now i am using an intent from another activity and getting to this(google) activity, i am getting Null pointer Exception. Please tell where am i going wrong.
public class Google extends Activity {
/** Called when the activity is first created. */
WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://www.google.com");
mWebView.setWebViewClient(new HelloWebViewClient());
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
}
}
You might have set a wrong layout here..
Make sure that your WebView is
main.xml.