我在java中遇到了问题,如果我使用serialize,它工作得很好,但是当我使用反序列化时,它抛出了一个java.lang.classnotfoundexception。
Exception in thread "main" java.lang.ClassNotFoundException: javatpointpractice.Information
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:606)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:168)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:468)
at java.base/java.io.ObjectInputStream.resolveClass(ObjectInputStream.java:782)
at java.base/java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:2028)
at java.base/java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1895)
at java.base/java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:2202)
at java.base/java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1712)
at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:519)
at java.base/java.io.ObjectInputStream.readObject(ObjectInputStream.java:477)
at deserializer.Deserializer.main(Deserializer.java:21)
public class Deserializer {
public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
Information ms = null;
FileInputStream fileInput = new FileInputStream("C:\\Users\\usetr\\Documents\\Java WorksSpace\\NETBEANS\\TutorialsPointPractice\\outputs.ser");
ObjectInputStream objectInput = new ObjectInputStream(fileInput);
ms = (Information) objectInput.readObject();
objectInput.close();
fileInput.close();
System.out.println(ms.name);
System.out.println(ms.age);
}
}
public class Information implements Serializable{
String name;
int age;
}
1条答案
按热度按时间kjthegm61#
你的类名应该是
Information
不MySerializable
现在您已经解决了这个问题,解决了这个类的编译问题,您的代码应该可以做您想要做的事情。