vnshetty
vnshetty

Reputation: 20132

Android application closed unexpectedly

I used the following code to download a file. It runs fine, but when I click the download button, the following error comes: "Application mibooks has stopped unexpectedly."

How can I solve this problem in my code?

package mds.mibooks;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.DownloadListener;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;


public class mibooks extends Activity {
    WebView mWebView;
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                 setContentView(R.layout.webview);

                 WebView myWebView = (WebView) findViewById(R.id.webView1);
                 WebSettings webSettings = myWebView.getSettings();
                 WebView myWebView1 = (WebView) findViewById(R.id.webView1);
                 myWebView1.setWebViewClient(new WebViewClient());
                 webSettings.setJavaScriptEnabled(true);


                /* WebView webView = (WebView) findViewById(R.id.webView1);
                 webView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
                */

            //   String summary = "<html><body>You scored <b>192</b> points.</body></html>";
                // myWebView1.loadData(summary, "text/html", "utf-8");
                 myWebView1.loadUrl("http://www.mibooks.com/beta/");


                 myWebView1.setDownloadListener(new DownloadListener() {
                        public void onDownloadStart(String url, String userAgent,
                                String contentDisposition, String mimetype,
                                long contentLength) {
                            Intent intent = new Intent(Intent.ACTION_VIEW);
                             intent.setData(Uri.parse("www.google.com"));
                   intent.setType("*zip*"); 
                            startActivity(intent);

                        }
                    });

            }    
        });
    }
}

Upvotes: 0

Views: 2835

Answers (2)

cristoph
cristoph

Reputation: 21

Perhaps install the ADT plugin? See here:- Cannot Make Andoid Apps Work

Upvotes: 1

vnshetty
vnshetty

Reputation: 20132

Android application stopped unexpectedly it is normal scenario in android programming when any runtime error is occurred. i was not aware of this when i was throwing this question. I got solution for this problem that is.. 1. setContentView(R.layout.webview); and setContentView(R.layout.main); one layout is point to null.

Upvotes: 1

Related Questions