java - 错误:枚举 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
解决方案
case
在 switch case 中不接受 Enum 类型(因为它是由编译器自动编写的):
switch(cell.getType()) {
case CELL_TYPE_NUMERIC:
// will compile as case Cell.CELL_TYPE_NUMERIC
//doSomething()
break;
default:
//doSomething()
}
按照这篇文章作为教程
推荐阅读
- swift - processEditing 上的自定义 NSTextStorage 性能瓶颈
- python - 在 Python 3.9.2 中删除嵌套字典中的键是否有一种紧凑的方法?
- python - 使用 pandas 从 excel 文件中读取数据时出错
- javascript - Vuejs中不显示密码字段的验证错误消息?
- python - 如何在 Python 的同一公式中使用列表列表的元素?
- python - 如何从 DataFrame 中删除多个索引?
- python - 使用 python 脚本创建 SQLite 中的列时未显示数据类型
- jenkins - 具有 ebextensions 的 NodeJS 应用程序未通过 Jenkins 作业部署到 Beanstalk
- javascript - javascript OR 操作似乎不适用于前两个选项
- php - 未定义索引:App\LoginToken {"userId":3,"exception":"[object] Laravel 8