【问题标题】:What does "cannot be resolved to a type" mean, and how can I fix it? Java Android 4.0“无法解析为类型”是什么意思,我该如何解决? Java安卓4.0
【发布时间】:2013-08-11 20:13:21
【问题描述】:

这是(应该是)在 Android 4.0 中实现对话框的简单示例。这个方法onCreateDialog()覆盖了从android.app.Dialog导入的同名方法;此代码不会编译并生成下面评论中显示的错误消息。此错误消息是什么意思,我该如何解决? 谢谢!

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case 0:
        return new AlertDialog.Builder(this)
        .setIcon(R.drawable.ic_launcher)
        .setTitle("This is a dialog with a stupid message...")
        .setPositiveButton("Dig it",

//error message:
//DialogInterface.onClickListener cannot be resolved to a type
            new DialogInterface.onClickListener() {
                public void onClick(DialogInterface dialog, int whichButton)
                {
                    Toast.makeText(getBaseContext(),
                            "Gotcha!", Toast.LENGTH_SHORT).show();
                }
            }
        )

【问题讨论】:

  • 你的意思是 - new DialogInterface().onClickListener()
  • 你漏了大写O,应该是DialogInterface.OnClickListener

标签: java android android-4.0-ice-cream-sandwich resolve


【解决方案1】:

正如错误试图告诉你的那样,没有名为 DialogInterface.onClickListener 的类型。

Java 区分大小写; you need a capital O.

【讨论】:

    猜你喜欢
    • 2011-11-05
    • 2021-07-14
    • 1970-01-01
    • 2015-10-19
    • 2014-07-05
    • 1970-01-01
    • 2020-04-20
    • 1970-01-01
    • 2013-12-08
    相关资源
    最近更新 更多