Mike Mike - 2 years ago 90
Java Question

my application keeps receiving "Unfortunately "My App" has stopped" after Running the app

After Implementing a WebView Client my application keep receiving "Unfortunately "My App" has stopped" after Running the app.
This is my maniefest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="amapps.com.uhss" >
<uses-permission android:name="android.permission.INTERNET"/>
android:label="UHS Sword And Shield"
android:theme="@style/AppTheme" >
android:label="UHS Sword and Shield" >

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />


As you can see I have already implemented the internet permissions

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends Activity {

private WebView mWebView = (WebView) findViewById(R.id.activity_main_webview);

protected void onCreate(Bundle savedInstanceState) {
WebView mWebView = (WebView) findViewById(R.id.activity_main_webview);
mWebView.setWebViewClient(new WebViewClient());

WebSettings webSettings = mWebView.getSettings();


So could someone please tell me what is wrong with my manifest or main activity.
My app was running before I implemented a WebView client into my app to handle opening links within my app. Thanks!

Answer Source

Remove line

private WebView mWebView = (WebView) findViewById(R.id.activity_main_webview); 


 public class MainActivity extends Activity

Whenever you want to initialize something, make sure you initialize them after setContentView . Your problem is that you initialized the webView twice, the first one you initialized after public class MainActivity extends Activity hence you will get nullpointerException error.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download