Java 对象序列化
我一直在尝试做一个对象序列化,反序列化程序。当我在FileInputStream中直接给出文件名时,我的程序运行得很好,并且成功地反序列化了对象。但是当我尝试使用FileDialog时,序列化程序运行得很好,但反序列化无法完成。我得到以下错误:Java 对象序列化,java,serialization,file-io,Java,Serialization,File Io,我一直在尝试做一个对象序列化,反序列化程序。当我在FileInputStream中直接给出文件名时,我的程序运行得很好,并且成功地反序列化了对象。但是当我尝试使用FileDialog时,序列化程序运行得很好,但反序列化无法完成。我得到以下错误: java.io.FileNotFoundException: nullnull (The system cannot find the file specified) at java.io.FileInputStream.open(Native Meth
java.io.FileNotFoundException: nullnull (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.io.FileInputStream.<init>(Unknown Source)
at package1.Deserialisation.main(Deserialisation.java:22)
Exception in thread "main" java.lang.NullPointerException
at package1.Deserialisation.main(Deserialisation.java:43) .
这将创建一个“nullnull”路径,表示这两个值都为null。
尝试使用fd1.show()代码>在上面一行之前
编辑:正如Viydha所指出的,show()已被弃用,应使用setVisible()
这将创建一个“nullnull”路径,表示这两个值都为null。
尝试使用fd1.show()代码>在上面一行之前
编辑:正如Viydha指出的,show()已被弃用,应使用setVisible()。错误出现在您的文件对话框中。该行:
String filepath = new String (fd.getDirectory()+fd.getFile());
创建nullnull
的路径。你应该做一个fd.show()代码>在这一行之前,或者最好使用错误在文件对话框中。该行:
String filepath = new String (fd.getDirectory()+fd.getFile());
创建nullnull
的路径。你应该做一个fd.show()代码>在这一行之前,或者更好,使用一个非常感谢…它起作用了…但是show()被弃用并替换为sestVisible()。非常感谢…它起作用了…但是show()被弃用并替换为sestVisible()
String filepath = new String (fd.getDirectory()+fd.getFile());