我有一个调用方法的线程,如果发生任何异常,它会返回到该线程的 catch 块。
稍后,我喜欢调用处理程序或 toast 消息来显示异常,但我无法调用它来显示错误。
我应该怎么做才能解决这个问题,任何想法。
提前致谢。
private void onSaveDialog() {
final ProgressDialog dialog = new ProgressDialog(this);
dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
dialog.setTitle("mApprove Advantage");
dialog.setIcon(R.drawable.mapprove1);
dialog.setMessage("Theme setting is in progress...");
dialog.setIndeterminate(false);
dialog.setCancelable(false);
dialog.show();
new Thread() {
@Override
public void run() {
try {
Thread.sleep(5000);
synchronized (this) {
onsave();
}
dialog.cancel();
onSetting();
} catch (Exception e) {
dialog.cancel();
wrongurl=true;
onFinishDialog1();
System.out.println("url wrong");
}
}
}.start();
}
private void onFinishDialog1(){
if(wrongurl){
wrongurl=false;
Toast.makeText(getApplicationContext(),
"URL not Available.", Toast.LENGTH_LONG)
.show();
}
}