嘿,我有这段代码应该保存一个java.util.Vector
自定义可序列化类:
if(filename.equals("")){
javax.swing.JFileChooser fc = new javax.swing.JFileChooser();
if(fc.showSaveDialog(this) == javax.swing.JFileChooser.APPROVE_OPTION){
filename = fc.getSelectedFile().toString();
}
}
try{
java.io.FileOutputStream fos = new java.io.FileOutputStream(filename);
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
java.io.ObjectOutputStream oos = new java.io.ObjectOutputStream(baos);
oos.writeObject((Object)tl.entities);
baos.writeTo(fos);
oos.close();
fos.close();
baos.close();
}catch(java.io.FileNotFoundException e){
javax.swing.JOptionPane.showMessageDialog(this, "FileNotFoundException: Could not save file: "+e.getCause()+" ("+e.getMessage()+")", "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
}catch(java.io.IOException e){
javax.swing.JOptionPane.showMessageDialog(this, "IOException: Could not save file: "+e.getCause()+" ("+e.getMessage()+")", "Error", javax.swing.JOptionPane.ERROR_MESSAGE);
}
但是在保存时,它显示一个定义的对话框错误说:IOException: Could not save file: null (com.sun.java.swing.plaf.windows.WindowsFileChooserUI)
并且NullPointerException
在命令行中有一个javax.swing.plaf.basic.BasicListUI.convertModelToRow(BasicListUI.java:1251)