我一直在做 TheNewBoston Java 教程,但陷入了 Enums 的困境,我无法绕过它。每次我尝试编译时,都会收到此错误 Thread [main](Suspended (exception NoSuchMethodError) pointing to line 5 in my Tuna Class. Here is my Tuna class and Apples class.
public enum Tuna
{
bucky("nice", "22"),
kelsey("cutie", "10"),
julia("mistake", "12");
private final String desc;
private final String year;
Tuna(String description, String birthday)
{
desc = description;
year = birthday;
}
public String getDesc()
{
return desc;
}
public String getYear()
{
return year;
}
}
public class Apples
{
public static void main(String[] args)
{
for(Tuna people: Tuna.values())
System.out.printf("%s\t%s\t%s\n", people, people.getDesc(), people.getYear());
}
}
我不知道我做错了什么。如果有的话,我正在使用 Ubuntu 13.10。
最佳答案
首先,您应该粘贴整个错误。 除此之外,我认为下面的行最后需要分号
改变这个
julia("mistake", "12"),
至
julia("mistake", "12");
你的类可能应该是这样的
public class Apples {
public enum Tuna {
bucky("nice", "22"),
kelsey("cutie", "10"),
julia("mistake", "12");
private final String desc;
private final String year;
Tuna(String description, String birthday) {
desc = description;
year = birthday;
}
public String getDesc() {
return desc;
}
public String getYear() {
return year;
}
}
public static void main(String[] args) {
for(Tuna people: Tuna.values())
System.out.printf("%s\t%s\t%s\n", people, people.getDesc(), people.getYear());
}
}
关于java - Eclipse 中的枚举 nosuchmethoderror,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22335784/