Reputation: 25
I'm trying to make a very basic app, just a webview and nothing else. I have barely any coding knowledge so I'm very lost. I downloaded Android Studio, and followed this tutorial, but whenever I ran it on a virtual device or my GS2 it would give me the "Unfortunately, this app has stopped working" message.
Here's all of the code that I've edited from the default template:
Anyone have any ideas why this is happening, or does anyone know of a different tutorial/template I can use?
Upvotes: 1
Views: 762
Reputation: 44571
As stated in a comment, you need to post the most relevant parts of the code and your logcat here when you get a crash. However, this was pretty easy so I will answer it this time. You are getting a NPE
because you are trying to call a method on a variable (mWebView
) before initializing it
webSettings = mWebView.getSettings(); // here will give a NPE
webSettings.setJavaScriptEnabled(true);
mWebView = (WebView) findViewById(R.id.activity_main_webview);
change that to
mWebView = (WebView) findViewById(R.id.activity_main_webview); //initialize first
webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
Upvotes: 1