Android的 - java.lang.IllegalArgumentException异常Erron在2.1和低的Andr​​oid创建对话框时,对话框、异常、lang、IllegalArgum

2023-09-07 16:35:40 作者:此用户已离线

我从Google手机是SDK版本和LT下面的错误信息; 8.我刚刚发布这个应用程序在Android Market上发布我的测试手机是一个HTC Thunderbolt和Droid的十事先既没有这个问题的。

我收到过乱舞这个错误报告。我不能够直接测试这个,因为我没有用SDK℃的电话; 8,由于某种原因,我不能让我的模拟器启动一个版本低于一个应用程序的默认SDK集。

java.lang.IllegalArgumentException异常,android.app.Activity.createDialog:880 - (活动#onCreateDialog没有创建ID 1对话框)

下面是onCreateDialog(INT ID),我已经实现。

  @覆盖
受保护的对话框onCreateDialog(INT ID){
    super.onCreateDialog(ID);
    对话对话框= NULL;

    开关(ID){
    情况1:
        对话框=新CustomCalcDialog(本);
        dialog.setTitle(输入发运%);
        activeTextView = shippingPercent;
        dialog.show();
        对话框= NULL;
        打破;
    案例2:
        对话框=新CustomCalcDialog(本);
        dialog.setTitle(请输入税率);
        activeTextView = taxPercent;
        dialog.show();
        对话框= NULL;
        打破;
    案例3:
        对话框=新CustomCalcDialog(本);
        dialog.setTitle(请输入佣金%);
        activeTextView = commissionPercent;
        dialog.show();
        对话框= NULL;
        打破;
    壳体4:
        对话框=新CustomCalcDialog(本);
        dialog.setTitle(计算小计);
        activeTextView = productSubtotal;
        dialog.show();
        对话框= NULL;
        打破;
    壳体5:
        对话框=新CustomCalcDialog(本);
        dialog.setTitle(额外的运输);
        activeTextView = addShipping;
        dialog.show();
        对话框= NULL;
        打破;
    情况6:
        对话框=新BackgroundOptionsDialog(本);
        dialog.setTitle(选择背景:);
        dialog.show();
        对话框= NULL;
        打破;
    默认:
        对话框= NULL;
    }
    返回对话框;
}
 

和下面是如何在对话框被驳回。

 私人无效registerListeners(){

        enterTotal.setOnClickListener(新View.OnClickListener(){

            @覆盖
            公共无效的onClick(视图v){
                尝试 {
                    calcLogic(等于);
                }赶上(例外前){}
                operatorChange = DONT_CHANGE;

                activeTextView.setText(calcDialogDisplay.getText()的toString());

                尝试 {
                    如果((Float.parseFloat(calcDialogDisplay.getText()的toString()))≤; 0){}
                }赶上(例外前){
                    activeTextView.setText(0);
                }
                mathCalculations();
                CustomCalcDialog.this.dismiss();
            }
        });
 

解决方案

有问题,还与以下解决它:

- 不要返回一个空对话框中的方法:保护对话框onCreateDialog(INT ID)

在Android 2.1系统中Activity.java错误时,有人就行871

 私人CreateDialog函数对话框(整数dialogId,捆绑状态){
869最后的对话对话框= onCreateDialog(dialogId);
870如果(对话== NULL){
871抛出新抛出:IllegalArgumentException(活动#onCreateDialog做
872 +没有为ID的对话框+ dialogId);
873}
874 dialog.dispatchOnCreate(州);
875返回对话框;
876}
 

如果你看后来的Andr​​oid有一个空对话的检查,它的handeld与回报。所以在这里它的工作原理。

- 不要使用包(以API8更改):

保护对话框onCreateDialog(INT ID,束束);

使用:

保护对话框onCreateDialog(INT ID);

- 我也用下面的检查(有一个特殊的情况下使用自定义对话框):

 如果(Build.VERSION.SDK_INT< = Build.VERSION_ codeS.ECLAIR_MR1){
        返回对话框;
    } 其他 {
        返回null;
    }
 

也许这可以帮助别人......

I'm getting the below error message from phones that are SDK version < 8. I just released this app on the android market and prior to release my test phones were a HTC Thunderbolt and the Droid X. Neither had this problem at all.

I'm getting this error report through Flurry. I'm not able to test this directly because I don't have a phone with SDK < 8 and for some reason I can't get my emulator to start a lower version than the default SDK set for an app.

java.lang.IllegalArgumentException, android.app.Activity.createDialog:880 - (Activity#onCreateDialog did not create a dialog for id 1)

Below is the onCreateDialog(int id) that i've implemented.

@Override
protected Dialog onCreateDialog(int id) {
    super.onCreateDialog(id);
    Dialog dialog = null;

    switch(id){
    case 1:
        dialog = new CustomCalcDialog(this);
        dialog.setTitle("Enter Shipping %");
        activeTextView = shippingPercent;
        dialog.show();
        dialog = null;
        break;
    case 2:
        dialog = new CustomCalcDialog(this);
        dialog.setTitle("Enter Tax Rate");
        activeTextView = taxPercent;
        dialog.show();
        dialog = null;
        break;
    case 3:
        dialog = new CustomCalcDialog(this);
        dialog.setTitle("Enter Commission %");
        activeTextView = commissionPercent;
        dialog.show();
        dialog = null;
        break;
    case 4:
        dialog = new CustomCalcDialog(this);
        dialog.setTitle("Calculate Subtotal");
        activeTextView = productSubtotal;
        dialog.show();
        dialog = null;
        break;
    case 5:
        dialog = new CustomCalcDialog(this);
        dialog.setTitle("Additional Shipping");
        activeTextView = addShipping;
        dialog.show();
        dialog = null;
        break;
    case 6:
        dialog = new BackgroundOptionsDialog(this);
        dialog.setTitle("Choose Background:");
        dialog.show();
        dialog = null;
        break;
    default:
        dialog = null;
    }
    return dialog;
}

And below is how the Dialog is being dismissed.

private void registerListeners () {

        enterTotal.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    calcLogic(EQUALS);
                }catch(Exception ex){}
                operatorChange = DONT_CHANGE;

                activeTextView.setText(calcDialogDisplay.getText().toString());

                try {
                    if ((Float.parseFloat(calcDialogDisplay.getText().toString())) < 0) {}
                }catch(Exception ex) {
                    activeTextView.setText("0");
                }
                mathCalculations();
                CustomCalcDialog.this.dismiss();
            }
        });

解决方案

Had the problem also and solved it with the following:

-Don't return a null Dialog in method: protected Dialog onCreateDialog(int id)

In Android 2.1 in Activity.java the error was raised on line 871.

private Dialog createDialog(Integer dialogId, Bundle state) {
869         final Dialog dialog = onCreateDialog(dialogId);
870         if (dialog == null) {
871             throw new IllegalArgumentException("Activity#onCreateDialog did "
872                     + "not create a dialog for id " + dialogId);
873         }
874         dialog.dispatchOnCreate(state);
875         return dialog;
876     }

If you look in later Android there is a check for a null Dialog and it's handeld with a return. So here it works.

-Don't use Bundle (changed in API8):

protected Dialog onCreateDialog(int id, Bundle bundle);

use:

protected Dialog onCreateDialog(int id);

-I also used the following check (had a special case with a custom dialog):

    if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.ECLAIR_MR1) {
        return dialog;
    } else {
        return null;
    }

Maybe it helps someone...