尝试调用此方法时出现错误:
okHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException e) {
runOnUiThread(new Runnable() {
@Override
public void run() {
showErrorAlert(e.toString());
}
});
}
//The Method:
public void showErrorAlert(String error) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(ProjectListActivity.this);
dialogBuilder.setMessage("Hmm, there seems to be an error downloading the project list. " + error);
dialogBuilder.setCancelable(true);
dialogBuilder.setPositiveButton(
"Okay",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = dialogBuilder.create();
alert.show();
}
因此,当呼叫失败时,它将立即崩溃,这是控制台中的输出:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.chimesoftware.chime.chimetimemanager, PID: 5770
android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@a9b7fff is not valid; is your activity running?
at android.view.ViewRootImpl.setView(ViewRootImpl.java:925)
at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:356)
at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:93)
at android.app.Dialog.show(Dialog.java:330)
at com.chimesoftware.chime.chimetimemanager.ProjectListActivity.showErrorAlert(ProjectListActivity.java:145)
at com.chimesoftware.chime.chimetimemanager.ProjectListActivity$1$1.run(ProjectListActivity.java:77)
at android.os.Handler.handleCallback(Handler.java:790)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6753)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:482)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
是否可以通过错误调用错误?或可能是因为我尝试显示的错误类型。
谢谢。
答案 0 :(得分:0)
var res = ResourceLoader.GetForCurrentView();
var deleteText = res.GetString("DeleteBlock/Text");
var confirmYes = res.GetString("ConfirmYes");
答案 1 :(得分:0)
如异常消息所示,当前活动已完成,但是您试图显示一个对话框,其中包含已完成活动的上下文。由于对话框没有窗口显示android运行时会引发此异常。
使用活动isFinishing()方法:
检查此活动是否正在完成中,这是因为您在该活动上调用了finish()还是其他人已要求完成该活动。
if(!isFinishing())
showDialog();
答案 2 :(得分:0)
它对我有用,如果您想使用它:
AlertDialog.Builder alertDialog = new AlertDialog.Builder(HelpAndSupport.this);
alertDialog.setTitle("Confirm Sign out...");
alertDialog.setMessage("Are you sure you want signout from Talentslist?");
alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//you posive click code here
}
});
alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.cancel();
}
});
alertDialog.show();