Results 1 to 2 of 2
  1. #1
    aianta is offline Member
    Join Date
    Apr 2011
    Posts
    63
    Rep Power
    0

    Default Saving Array Error

    Im trying to save an array via ObjectOutputStream, and Im getting the following error:

    Java Code:
    java.io.NotSerializableException: differentialAlgorithm_Frameowrk.Thing
    	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    	at java.io.ObjectOutputStream.writeArray(Unknown Source)
    	at java.io.ObjectOutputStream.writeObject0(Unknown Source)
    	at java.io.ObjectOutputStream.writeObject(Unknown Source)
    	at differentialAlgorithm_Frameowrk.SaveSystem.save(SaveSystem.java:25)
    	at differentialAlgorithm_Frameowrk.Algorithm_Main.main(Algorithm_Main.java:56)

    Here is the save code:

    Java Code:
    	public void save(Thing[] saveDataArray){
    		
    		FileOutputStream fos = null;
    		try {
    			fos = new FileOutputStream("savedata.tmp");
    		} catch (FileNotFoundException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		try {
    			ObjectOutputStream oos = new ObjectOutputStream(fos);
    			
    			oos.writeObject(saveDataArray);
    			oos.close();
    			
    		} catch (IOException e) {
    			// TODO Auto-generated catch block
    			e.printStackTrace();
    		}
    		
    	}
    Im not sure whats wrong...

  2. #2
    ozzyman's Avatar
    ozzyman is offline Senior Member
    Join Date
    Mar 2011
    Location
    London, UK
    Posts
    797
    Blog Entries
    2
    Rep Power
    4

    Default

    When writing serialized objects, All sub-objects must be serializeable also. If it shouldn't be serialised then mark it 'transient'.

    differentialAlgorithm_Frameowrk.Thing is not Serializeable so the main object cannot be serialized because it contains 'Thing'

Similar Threads

  1. Saving from, and loading to an array.
    By VisionIncision in forum New To Java
    Replies: 4
    Last Post: 11-23-2010, 10:47 AM
  2. array error
    By blu_fox88 in forum New To Java
    Replies: 4
    Last Post: 04-25-2010, 01:18 PM
  3. Can't Solve Array Error
    By Gregadeaux in forum New To Java
    Replies: 2
    Last Post: 12-14-2009, 04:01 AM
  4. Error in saving an Image????
    By LankanSniper in forum Java 2D
    Replies: 4
    Last Post: 11-07-2009, 05:48 AM
  5. Replies: 4
    Last Post: 03-12-2009, 12:25 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
  •