Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 重写时android 4 onCreateDialog返回类型不兼容_Java_Android - Fatal编程技术网

Java 重写时android 4 onCreateDialog返回类型不兼容

Java 重写时android 4 onCreateDialog返回类型不兼容,java,android,Java,Android,下面的代码无法编译。我知道,在执行覆盖时 替换类必须与原始类的签名完全匹配, 但我认为我正在仔细地遵循Android文档中的示例 错误消息: overrides android.app.Activity.onCreateDialog The return type is incompatible with Activity.onCreateDialog(int) @Override protected Dialog onCreateDialog(int id) { switch (id

下面的代码无法编译。我知道,在执行覆盖时 替换类必须与原始类的签名完全匹配, 但我认为我正在仔细地遵循Android文档中的示例

错误消息:

overrides android.app.Activity.onCreateDialog
The return type is incompatible with Activity.onCreateDialog(int)
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case 0:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setIcon(R.drawable.ic_launcher)
            .setTitle("This is a dialog with a stupid message...")

            //more code here setting additional properties
            );
    return builder.create();
    }
}
onCreateDialog()
方法:

overrides android.app.Activity.onCreateDialog
The return type is incompatible with Activity.onCreateDialog(int)
@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case 0:
        AlertDialog.Builder builder = new AlertDialog.Builder(this);

        builder.setIcon(R.drawable.ic_launcher)
            .setTitle("This is a dialog with a stupid message...")

            //more code here setting additional properties
            );
    return builder.create();
    }
}

您需要在交换机中设置一个默认返回块,或者在交换机后设置一个返回块。在这些情况下,可以返回null

方法需要一个Bundle作为参数,而不是int。您应该传入一个包含int id的Bundle,并从Bundle中检索该值,以便在switch语句中使用。

我想可以,但这在很久以前就被贬低了。看:@ShobhitPuri啊,谢谢。我不知道。因此,这可能取决于APITo是否清楚,不推荐使用不带额外
Bundle
参数的整数id。我可能一直在考虑使用DialogFragments时使用的onCreateDialog方法。