DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2007

    Problems with my object serialization

    Hi everyone,

    Im trying to store an arraylist by serializing it.

    The problem is, that it wont work, im getting the not serializable exception:
    java.io.NotSerializableException: ImageResults
    	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    	at java.io.ObjectOutputStream.writeObject(Unknown Source)
    	at java.util.ArrayList.writeObject(Unknown Source)
    	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    	at java.lang.reflect.Method.invoke(Unknown Source)
    	at java.io.ObjectStreamClass.invokeWriteObject(Unknown Source)
    Is there any way around this? do i need to serialize every object in the arraylist or something? My serialising class and the class of the objects which are found in the arraylist are below:

    please help - thanks

    The class where i serialize the arraylist
    import java.io.*;
    import java.util.*;
    public class FeatureDatabase {
    	public void writeToDatabase (ArrayList imageResults) {
    		for (int i=0; i<imageResults.size(); i++) {
    			ImageResults ir = (ImageResults)imageResults.get(i);			
    		ObjectOutput output = null;
    		try {
    			// use buffering
    			OutputStream file = new FileOutputStream("FeatureDatabase.db");
    			OutputStream buffer = new BufferedOutputStream(file);
    			output = new ObjectOutputStream(buffer);
    		catch (IOException ex) {
    			System.out.println("\n\nCannot perform output: "+ex.getLocalizedMessage());
    		finally {
    			try {
    				if (output != null) {
    					// flush and close "output" and its underlying streams
    			catch (IOException ex) {
    				System.out.println("Cannot close output stream.");
    	public ArrayList getDatabase () {}

    My arraylist which im trying to serialize is full of these objects:
    Do i need to make this class extend serializable???????
    import java.util.Vector;
    public class ImageResults {
    	public String name;
    	public String location;
    	private Vector ccvResults;
    	private Vector acResults;
    	private Vector dctResults;
    	private Vector gmResults;
    	private Vector histogramResults;
    	private Vector miResults;
            /* getter and setter methods */

  2. #2
    Join Date
    Dec 2004
    San Bernardino County, California
    Yes ... the error is telling you that you need to make your ImageResults class implement the Serializable interface. This interface is like Cloneable: there are no methods to implement, you just need to explicitly state that the class can be serialized.

Similar Threads

  1. Problems with search object in Outlook
    By amotto in forum VB Classic
    Replies: 0
    Last Post: 02-14-2006, 09:46 AM
  2. Replies: 1
    Last Post: 07-23-2001, 04:07 AM
  3. Problems using a COM+ object from Windows 98 Clients
    By John Garcia in forum VB Classic
    Replies: 1
    Last Post: 07-19-2001, 11:23 AM
  4. A creates-->B,C. B call-> A call-> C?
    By rneal in forum Java
    Replies: 2
    Last Post: 12-12-2000, 10:41 AM
  5. Re: Passing an object name through a variable
    By mrfelis in forum VB Classic
    Replies: 9
    Last Post: 04-25-2000, 10:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.