我在我的应用程序中已经有了这个异常,但是我想在这里创建一个自定义对话框,这是我的异常:
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();
}但如果没有运气,它没有显示自定义对话框,什么可以推荐我这样做?
非常感谢。
发布于 2012-10-11 07:04:30
看到它,也许它能帮助你;)
如何捕捉“java.lang.RuntimeException”或抛出和捕获异常
发布于 2012-10-11 07:10:22
如果对话框中有一个已经弹出的自定义消息,它会工作吗?如果是,那么您可能希望在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;
}
}https://stackoverflow.com/questions/12833761
复制相似问题