首页 > 解决方案 > 错误:枚举 switch case 标签必须是枚举常量 case Cell.CELL_TYPE_NUMERIC 的非限定名称

问题描述

所以我仍然是编程和Java的初学者。我目前是一名高中实习生的公司有一个即将到来的项目。该项目的一部分是读取 excel 文件并将数据存储在变量中以供以后使用。

为了了解有关文件读写的更多信息,我尝试了我在互联网上找到的代码来实现一次,然后查看它们以了解其中发生了什么。问题是,大多数在线代码显示多个语法错误并且直接不起作用。没有任何真正的分步指南来解释读取 Excel 文件究竟需要什么以及如何为此编写代码。

由于我太笨了,无法弄清楚该站点上的格式,因此这是出现问题的部分代码的图像。

显然除了不合格的枚举之外似乎没有语法问题。我正在使用 NetBeans IDE,它只突出显示以下三个:

1) Cell.CELL_TYPE_NUMERIC: error: an enum switch case label must be the unqualified name of an enumeration constant case Cell.CELL_TYPE_NUMERIC

2) Cell.CELL_TYPE_STRING:error: an enum switch case label must be the unqualified name of an enumeration constant case Cell.CELL_TYPE_STRING

3) Cell.CELL_TYPE_BOOLEAN:error: an enum switch case label must be the unqualified name of an enumeration constant case Cell.CELL_TYPE_BOOLEAN

标签: java

解决方案


case在 switch case 中不接受 Enum 类型(因为它是由编译器自动编写的):

switch(cell.getType()) {
  case CELL_TYPE_NUMERIC:
  // will compile as case Cell.CELL_TYPE_NUMERIC
    //doSomething()
    break;
  default:
    //doSomething()
}

按照这篇文章作为教程


推荐阅读