MarteJ
asked on
NotSerializableException message for class wich implements Serializable
Hi,
I have an application communicating with a servlet. The servlet passes a Vector of objects of the class AnnoTemplate. This class implements Serializable. But I still get the following exception:
java.io.WriteAbortedExcept ion: writing aborted; java.io.NotSerializableExc eption: triq_adb.atv.gui.AnnoTempl ate
at java.io.ObjectInputStream. readObject 0(ObjectIn putStream. java:1278)
at java.io.ObjectInputStream. readArray( ObjectInpu tStream.ja va:1603)
at java.io.ObjectInputStream. readObject 0(ObjectIn putStream. java:1271)
at java.io.ObjectInputStream. defaultRea dFields(Ob jectInputS tream.java :1845)
at java.io.ObjectInputStream. readSerial Data(Objec tInputStre am.java:17 69)
at java.io.ObjectInputStream. readOrdina ryObject(O bjectInput Stream.jav a:1646)
at java.io.ObjectInputStream. readObject 0(ObjectIn putStream. java:1274)
at java.io.ObjectInputStream. readObject (ObjectInp utStream.j ava:324)
etc.
It used to work, but suddenly I get an exception. AnnoTemplate contains only int's, boolean's and String's, so I assume I don't need to let other classes implement Serializable.
My servlet:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
ObjectOutputStream outputToATV = new ObjectOutputStream(respons e.getOutpu tStream()) ;
Vector _templates = new Vector();
...
//Successfull reading of xml file with JAXB, createing objects of AnnoTemplate by calling setAnnoTemplate() and adding these to _templates Vector.
...
outputToATV.writeObject(_t emplates);
outputToATV.flush();
outputToATV.close();
outputToATV.flush();
outputToATV.close()
} catch(Exception x) {
x.printStackTrace();
}
AnnoTemplate class:
package triq_adb.atv.gui;
import java.io.Serializable;
public class AnnoTemplate implements Serializable {
// public static final int's and String's
private String _name;
private String _type;
private String _category;
private String _remark;
private String _severity;
private boolean _pending;
public AnnoTemplate() {
// Initialize the annotation template
_name = new String("");
_type = new String("");
_category = new String("");
_remark = new String("");
_severity = 0;
_pending = false;
}
public void setAnnoTemplate(String name, String type, String category, String remark,
String severity) {
_setName(name);
_setType(type);
_setCategory(category);
_setRemark(remark);
_setSeverity(severity);
_setSeismicDataType(seismi cDataType) ;
}
private void _setName(String s) {
_name = s;
}
public String getName() {
return _name;
}
private void _setType(String s) {
_type = s;
}
public String getType() {
return _type;
}
private void _setCategory(String s) {
_category = s;
}
public String getCategory() {
return _category;
}
private void _setRemark(String s) {
_remark = s;
}
public String getRemark() {
return _remark;
}
private void _setSeverity(String s) {
_severity = s;
}
public String getSeverity() {
return _severity;
}
private void _setPending(boolean flag) {
_pending = flag;
}
public boolean getPending() {
return _pending;
}
}
Greatful for help, cause I am stuck!!:-)
I have an application communicating with a servlet. The servlet passes a Vector of objects of the class AnnoTemplate. This class implements Serializable. But I still get the following exception:
java.io.WriteAbortedExcept
at java.io.ObjectInputStream.
at java.io.ObjectInputStream.
at java.io.ObjectInputStream.
at java.io.ObjectInputStream.
at java.io.ObjectInputStream.
at java.io.ObjectInputStream.
at java.io.ObjectInputStream.
at java.io.ObjectInputStream.
etc.
It used to work, but suddenly I get an exception. AnnoTemplate contains only int's, boolean's and String's, so I assume I don't need to let other classes implement Serializable.
My servlet:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
ObjectOutputStream outputToATV = new ObjectOutputStream(respons
Vector _templates = new Vector();
...
//Successfull reading of xml file with JAXB, createing objects of AnnoTemplate by calling setAnnoTemplate() and adding these to _templates Vector.
...
outputToATV.writeObject(_t
outputToATV.flush();
outputToATV.close();
outputToATV.flush();
outputToATV.close()
} catch(Exception x) {
x.printStackTrace();
}
AnnoTemplate class:
package triq_adb.atv.gui;
import java.io.Serializable;
public class AnnoTemplate implements Serializable {
// public static final int's and String's
private String _name;
private String _type;
private String _category;
private String _remark;
private String _severity;
private boolean _pending;
public AnnoTemplate() {
// Initialize the annotation template
_name = new String("");
_type = new String("");
_category = new String("");
_remark = new String("");
_severity = 0;
_pending = false;
}
public void setAnnoTemplate(String name, String type, String category, String remark,
String severity) {
_setName(name);
_setType(type);
_setCategory(category);
_setRemark(remark);
_setSeverity(severity);
_setSeismicDataType(seismi
}
private void _setName(String s) {
_name = s;
}
public String getName() {
return _name;
}
private void _setType(String s) {
_type = s;
}
public String getType() {
return _type;
}
private void _setCategory(String s) {
_category = s;
}
public String getCategory() {
return _category;
}
private void _setRemark(String s) {
_remark = s;
}
public String getRemark() {
return _remark;
}
private void _setSeverity(String s) {
_severity = s;
}
public String getSeverity() {
return _severity;
}
private void _setPending(boolean flag) {
_pending = flag;
}
public boolean getPending() {
return _pending;
}
}
Greatful for help, cause I am stuck!!:-)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Also, is this a typo? (two pairs )
>>
outputToATV.flush();
outputToATV.close();
outputToATV.flush();
outputToATV.close()
>>
>>
outputToATV.flush();
outputToATV.close();
outputToATV.flush();
outputToATV.close()
>>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
:-)
:)
Can you post the reading code ?