0

我的应用程序中已经有此异常,但我想创建一个自定义对话框,这是我的异常:

10-11 01:41:49.420: E/AACPlayer(649): playAsync():
10-11 01:41:49.420: E/AACPlayer(649): java.lang.RuntimeException: 
Cannot start native decoder

而不是显示这个java.lang.RuntimeException: Cannot start native decoder to person,像错误一样显示!!流已关闭。

我试过这样的事情:

 try
        {
            aacPlayer.playAsync( getUrl());
        }
        catch(Exception e)
        {
            AlertDialog alertDialog = new AlertDialog.Builder(Activity.this).create();
            alertDialog.setTitle("Error in radio");
            alertDialog.setMessage("out of service");
            alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
               public void onClick(DialogInterface dialog, int which) {
                  // here you can add functions
               }
            });
            alertDialog.setIcon(R.drawable.icon);
            alertDialog.show();
        }

但没有运气它不显示自定义对话框有什么可以推荐我呢?

非常感谢。

4

2 回答 2

1

看看吧,也许它可以帮助你;)

如何捕获“java.lang.RuntimeException”抛出和捕获异常

于 2012-10-11T07:04:30.347 回答
1

如果对话框中已经弹出自定义消息,它会起作用吗?如果是,那么您可能希望在 catch 块中执行此操作:

CustomException ce = new CustomException();
throw ce;

并有一个像这样的自定义异常

public static class CustomException extends Exception {

    String errorMsg; // this is the string that the your alert box will show

    public CustomException() {
        super();
        errorMsg = "YOU DID THIS ALL"; // set string here for your custom message
    }

    public CustomException(String err) { // set custom string in the constructor itself
        super(err);
        errorMsg = err;
    }

    public String getError() {
        return errorMsg;
    }

    public String toString() {
        return errorMsg;
    }
}
于 2012-10-11T07:10:22.590 回答