我有这个例外,我不明白为什么。错误日志:
java.io.NotSerializableException: java.io.ObjectOutputStream
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1184)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:348)
at handballapp.HandballApp.main(HandballApp.java:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
主类,问题似乎在out.writeObject(out);,所以我想这是输出格式问题或类似的问题:
public class HandballApp extends Application{
public static void main(String[] args) {
ArrayList<Equipe> str = new ArrayList<>();
str.add(new Equipe("Paris-SG", "D1", 1, 22, 11, 11, 0, 0, 378, 301, "Raul Gonzalez Gutierrez", "Jesus Gonzalez Fernandez"));
File f = new File("team.txt");
try {
FileOutputStream fos = new FileOutputStream(f);
ObjectOutputStream out = new ObjectOutputStream(fos);
out.writeObject(out);
out.close();
fos.close();
System.out.println("Data write successfully !");
} catch (FileNotFoundException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
我的班级装备:
public class Equipe implements Serializable{
private String nom;
private String ligue;
private int classement;
private int pts;
private int matchJouer;
private int victoire;
private int defaite;
private int matchNul;
private int butPour;
private int butContre;
private String entraineur;
private String entraineurAdj;
}
[如果有人可以提供帮助,我认为错误只是Equipe实施的,但我似乎不是。