Trying to make a basic webview android app - crash on startup

user3264252

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:

http://pastebin.com/MAi4aJR6

Anyone have any ideas why this is happening, or does anyone know of a different tutorial/template I can use?

codeMagic

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);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related