enum valueOf IllegalArgumentException:没有枚举 const 类
我过去在java中使用过枚举,但由于某种原因我现在遇到了一个奇怪的错误。它抛出错误的代码行是:
switch(ConfigProperties.valueOf(line[0].toLowerCase()){
...
}
我在示例行中得到的
java.lang.IllegalArgumentException: No enum const class
allautomator.ConfigProperties.language
是一个字符串数组。
我现在真的很困惑,我不知道可能出了什么问题。
I have used enums in java in the past but for some reason I am getting a strange error right now. the Line of code that it is throwing the error is:
switch(ConfigProperties.valueOf(line[0].toLowerCase()){
...
}
I am getting a
java.lang.IllegalArgumentException: No enum const class
allautomator.ConfigProperties.language
in the example line is an array of Strings.
I am just really confused right now, I do not know what could possibly be wrong.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
枚举常量区分大小写,因此请确保常量确实是小写的。另外,我建议您对输入进行
trim()
处理,以确保其中没有前导/尾随空白:作为参考,这里是一个包含您的行的工作示例程序:
输出:
The enum constants are case sensitive, so make sure you're constants are indeed lower case. Also, I would suggest that you
trim()
the input as well to make sure no leading / trailing white-space sneak in there:For reference, here is a working sample program containing your line:
Output:
我使用类似的概念,但有一个默认值以防失败
I am using a similar concept, but having a default value in case of fail