我的应用程序中已经存在此异常,但我想创建一个自定义对话框 继承我的例外:
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:无法启动本机解码器给人,显示错误!!流下来了。
我试过这样的事情: 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();
}
但没有运气,它没有显示可以推荐我的自定义对话框吗?
非常感谢。
答案 0 :(得分:1)
答案 1 :(得分: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;
}
}