我已決定將所有對話放在Notify類中。從另一個類調用AlertDialog
然而,當我嘗試調用一個對話框,應用程序崩潰
這是通知類:
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 notify = new Notify();
notify.messageBox("Test Title", "Test Message");
你有沒有想過這個?我遇到了同樣的事情。 –