1

我决定将所有对话框放在 Notify 类中。

但是,当我尝试调用对话框时,应用程序崩溃

这是通知类:

public class Notify extends Activity
{


public void  errorHandler(String title, Exception e)
{
    eH(title, e);
}

public void  messageBox(String title, String details)
{
    alertDialog(title, details);
}

    //***************************************************************
//display error dialog.
//****************************************************************
private void eH(String method, Exception e)
{
    Log.e("FIRSTDROID EXCEPTION", method + " : " + e.getMessage());

    e.printStackTrace();

    AlertDialog alertDialog;
    alertDialog = new AlertDialog.Builder(this).create();
    alertDialog.setTitle(method);
    alertDialog.setMessage(e.getMessage());
    alertDialog.setIcon(R.drawable.quiticon);
    alertDialog.setCanceledOnTouchOutside(true);
    alertDialog.show();
}


//*************************************************************
//generic dialog for messages to the user
//*************************************************************
private void alertDialog(String title, String message)
{       
    Log.i("Message", message);

    AlertDialog.Builder messageBox;
    messageBox = new AlertDialog.Builder(null);
    messageBox.setTitle(title);
    messageBox.setMessage(message);
    messageBox.setIcon(R.drawable.infoicon);
    messageBox.setNeutralButton("OK", null);
    messageBox.setCancelable(false);
    messageBox.show();
}

我创建了一个新的 Notify 实例,并调用 messageBox,如下所示:

Notify notify = new Notify();

notify.messageBox("Test Title", "Test Message");
4

2 回答 2

0

android.app.AlertDialog.Builder.Builder(Context context), so u need transfer this or ApplicationContext just like eH() method,

alertDialog = new AlertDialog.Builder(this).create();

for another, why do u create one activity and call its public method? what's the meaning, I hava no idea about it.

于 2013-08-16T08:53:57.587 回答
0

You forget .create() in your alertDialog method while you are initializing the messageBox variable. This might lead to crash in your application. And you should pass the Context in AlertDialog.Builder like messageBox = new AlertDialog.Builder(getApplicationContext()); or messageBox = new AlertDialog.Builder(this);

于 2013-08-16T08:54:13.633 回答