0

I've made this code. Whenever the "ok" button is pressed in the dialog, the app crashes with said exception. I can't figure out why, any help? I've followed these instructions from the Android documentation.

package com.grawl.faqplus;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class FAQPlusActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        // Set up buttons

        Button buttonExit = (Button) findViewById(R.id.button_exit);
        Button buttonAbout = (Button) findViewById(R.id.button_about);

        // Set up AlertDialog for buttonAbout

        String aboutMessage = (String) getString(R.string.dialog_about);

        AlertDialog.Builder builderAbout = new AlertDialog.Builder(this);
        builderAbout.setMessage(aboutMessage);
        builderAbout.setCancelable(false);
        builderAbout.setNeutralButton("OK!", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int id) {
                finish();
            }
        });
        final AlertDialog alertAbout = builderAbout.create();

        // Show about dialog

        buttonAbout.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                alertAbout.show();
            }
        });

        // Exit app

        buttonExit.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                finish();
                System.exit(0);
            }
        });      
    }
}
Johan
  • 318
  • 2
  • 9
Grawl
  • 53
  • 2
  • 5

1 Answers1

2

I fixed it by replacing

finish();

with

dialog.dismiss();
Grawl
  • 53
  • 2
  • 5