[英]Android - Alert Dialog Force Close error
我在Google上搜索了很多,卻沒有找到解決方案。 我使用帶有電子郵件EditText
和兩個按鈕Submit和Cancel的警報對話框,並根據情況需要顯示不同的警報。 但即時通訊收到強制關閉錯誤, logcat
顯示:
05-16 13:16:48.281: E/AndroidRuntime(13572): java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
05-16 13:16:48.281: E/AndroidRuntime(13572): at android.view.ViewGroup.addViewInner(ViewGroup.java:1976)
05-16 13:16:48.281: E/AndroidRuntime(13572): at android.view.ViewGroup.addView(ViewGroup.java:1871)
05-16 13:16:48.281: E/AndroidRuntime(13572): at android.view.ViewGroup.addView(ViewGroup.java:1851)
下面是在警報對話框中顯示警報對話框的代碼:
forgotPasswordMailAlert()是:
private void forgotPasswordMailAlert(String AlertText)
{
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(AlertText)
.setCancelable(true)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
我也在Stackoverflow中搜索了很多。 您能在需要更改代碼的地方幫我嗎? 請幫助我如何解決此問題。
使用alert.dismiss(); 而不是dialog.dismiss();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.