Есть ли способ убедиться, что сериализация объекта выполнена правильно?Я создал апплет, который сериализовал методом writeObject()
, и у меня нет исключений и ошибок.Но когда я пытаюсь десериализовать его с readObject()
, я получаю исключение NullPointerException.Мой апплет довольно сложный, но я гарантировал, что все мои поля сериализуемы.
В классе возражения есть вложенные классы.
Есть предположения относительно того, что могло бы произойти?
приведенный ниже код в моем сервлете создает SerialTree.
` SerialTree st = new SerialTree() ;
try{
ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("/home/cof/test8"));
out.writeUnshared(st);
out.flush();
out.close();
}
Вот трассировка стека:
java.lang.NullPointerException
at java.awt.Container.readObject(Container.java:3575)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:991)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1865)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1770)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1684)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1340)
at java.io.ObjectInputStream.access$300(ObjectInputStream.java:205)
at java.io.ObjectInputStream$GetFieldImpl.readFields(ObjectInputStream.java:2125)
at java.io.ObjectInputStream.readFields(ObjectInputStream.java:536)
at java.awt.Container.readObject(Container.java:3560)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:991)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1865)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1770)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1684)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1340)
at java.io.ObjectInputStream.access$300(ObjectInputStream.java:205)
at java.io.ObjectInputStream$GetFieldImpl.readFields(ObjectInputStream.java:2125)
at java.io.ObjectInputStream.readFields(ObjectInputStream.java:536)
at java.awt.Container.readObject(Container.java:3560)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:991)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1865)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1770)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1684)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1340)
at java.io.ObjectInputStream.access$300(ObjectInputStream.java:205)
at java.io.ObjectInputStream$GetFieldImpl.readFields(ObjectInputStream.java:2125)
at java.io.ObjectInputStream.readFields(ObjectInputStream.java:536)
at java.awt.Container.readObject(Container.java:3560)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:991)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1865)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1770)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1684)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1340)
at java.io.ObjectInputStream.access$300(ObjectInputStream.java:205)
at java.io.ObjectInputStream$GetFieldImpl.readFields(ObjectInputStream.java:2125)
at java.io.ObjectInputStream.readFields(ObjectInputStream.java:536)
at java.awt.Container.readObject(Container.java:3560)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:991)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1865)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1770)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1684)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1340)
at java.io.ObjectInputStream.access$300(ObjectInputStream.java:205)
at java.io.ObjectInputStream$GetFieldImpl.readFields(ObjectInputStream.java:2125)
at java.io.ObjectInputStream.readFields(ObjectInputStream.java:536)
at java.awt.Container.readObject(Container.java:3560)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:991)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1865)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1770)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1684)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1340)
at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1963)
at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1887)
at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1770)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1346)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:368)
at arbre.ArbreClient.getHttpObject(ArbreClient.java:92)
at arbre.ArbreClient.init(ArbreClient.java:123)
at sun.applet.AppletPanel.run(AppletPanel.java:436)
at java.lang.Thread.run(Thread.java:636)
здесьстроки с 70 по 106 для самого апплета, он пытается получить объект serilaTree?
`try {result = new ObjectInputStream (new FileInputStream (" / home / cof / test8 "));
}
catch(NotSerializableException e){
e.printStackTrace();
}
catch(InvalidClassException e){
e.printStackTrace();
}
catch(StreamCorruptedException e){
e.printStackTrace();
}
catch(NotActiveException e){
e.printStackTrace();
}
catch(OptionalDataException e){
e.printStackTrace();
}
Object obj =null;
try{
obj = result.readObject();
}
catch(NullPointerException e){
e.printStackTrace();
// System.out.println("lalal");
}
catch(NotSerializableException e){
e.printStackTrace();
}
catch(InvalidClassException e){
e.printStackTrace();
}
catch(StreamCorruptedException e){
e.printStackTrace();
}