我有一个像这样的Enumeration类:
public enum Elementi {
IDROGENO("H", 1, 1.008),
ELIO("He", 2, 4.003),
// ... altri elementi
LITIO("Li", 3, 6.491);
private int numeroAtomico;
private double massaAtomica;
private String simbolo;
public int getNumeroAtomico() {
return numeroAtomico;
}
public String getSimbolo() {
return simbolo;
}
private Elementi(String simbolo, int numeroAtomico, double massaAtomica){
this.simbolo = simbolo;
this.numeroAtomico = numeroAtomico;
this.massaAtomica = massaAtomica;
}
}
在另一个文件中,我有一个像这样的主程序:
import java.util.Elementi;
public class Main{
public static void main (String[] args){
for (Elementi e: Elementi.values())
System.out.println("%s\t|\t%d|\t%s\n", e.getSimbolo(),e.getNumeroAtomico(), e);
}
}
如果我编译并执行这两个文件,我会收到以下错误:
-Main.java:1: error: cannot find symbol
import java.util\\\.\\\Elementi;
symbol: class Elementi
location: package java.util
-Main.java:7: error: no suitable method found for println (String, String, int, Elementi)
System.out\\\.\\\println("%s\t|\t%d|\t%s\n", e.getSimbolo(), e.getNumeroAtomico(), e);
Method PrintStream.println(Object) is not applicable
(actual and formal argument lists differ in lenght)
Method PrintStream.println(String) is not applicable
(actual and formal argument lists differ in lenght)
Method PrintStream.println(char[]) is not applicable
(actual and formal argument lists differ in lenght)
Method PrintStream.println(double) is not applicable
(actual and formal argument lists differ in lenght)
Method PrintStream.println(float) is not applicable
(actual and formal argument lists differ in lenght)
Method PrintStream.println(long) is not applicable
(actual and formal argument lists differ in lenght)
Method PrintStream.println(int) is not applicable
(actual and formal argument lists differ in lenght)
Method PrintStream.println(char) is not applicable
(actual and formal argument lists differ in lenght)
Method PrintStream.println(boolean) is not applicable
(actual and formal argument lists differ in lenght)
Method PrintStream.println() is not applicable
(actual and formal argument lists differ in lenght)
2 errors
我将两个错误放在\\之间,如下所示: \\错误\\
我会解决这些问题
感谢所有
答案 0 :(得分:0)
Elementi
不在java.util
包中。用适当的包装进口。System.out.println()
不接受varargs和格式化字符串。请改用System.out.printf()
。