我有以下行错误:Java错误日食排序
Collections.sort(l);
你能解释一下为什么吗?
这是程序代码:
import java.io.*;
import java.util.*;
public class Esame{
public static void main(String args[]) throws IOException{
ArrayList<Studente> l=new ArrayList<Studente>();
BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
String cognome = b.readLine();
while(!cognome.equals("")){
System.out.println("inserire nome");
String nome = b.readLine();
System.out.println("inserire matricola");
String matricola = b.readLine();
Studente s = new Studente(nome, cognome, matricola);
l.add(s);
System.out.println("inserire cognome");
cognome = b.readLine();
}
b.close();
Collections.sort(l);
Iterator<Studente> i=l.iterator();
PrintStream p=new PrintStream(new File("uscita.txt"));
while(i.hasNext()){
p.println(i.hasNext());
}
p.close();
}
}
class Studente{
protected String nome,cognome;
protected int matricola;
public Studente(String nome,String cognome,String matricola){
this.nome=nome;
this.cognome=cognome;
this.matricola=Integer.parseInt(matricola);
}
public String toString(){
return "\n NOME: "+nome+"Cognome: "+cognome+"MATRICOLA: "+matricola;
}
public int compareTo(Object x) {
Studente p = (Studente) x;
return cognome.compareTo(p.cognome);
}
}
打印控制台输出,所以我们可以读取异常请。 –
什么是错误?是否堆栈跟踪,然后请张贴,或者如果它的日食错误比张贴屏幕截图 –
我有@override尝试,但是,不会改变任何东西:错误是这样的:异常在线程“主要”java.lang.Error:未解决编译问题: \t的方法排序(名单)在类型集合不适用于参数(ArrayList的) \t在Esame.main(Esame.java:31) –