Categories: java, arrays, xml, object, serializable

Save Array of 2nd Object with Java Serializable

1 answer

i've got a class called "Settings" which has an array of "UniverseOut".

private static final long serialVersionUID = 2929431155275389116L;  private String projectName = "last-project";  private UniverseOut[] universeOut = new UniverseOut[unicastLimit]; 

When i change the "projectName" in the settings class via a command, it changes it and when i save the project, and restart the application it will read the name perfectly without any mistakes.

But the UniverseOut Array isnt being saved at all, it just says that the array is from that type but the values/object itself isnt saved.

public class UniverseOut implements Serializable {  /**  *   */ private static final long serialVersionUID = -1326425548448853224L; private static final int max_ip = 10; private static String[] ip = new String[max_ip];  } 

And this is the code how i save the objects as XML Files:

        String path = System.getProperty("user.dir");         FileOutputStream fos = new FileOutputStream(path + "\\" + projectname + ".project");         XMLEncoder xml = new XMLEncoder(fos);         xml.setExceptionListener(new ExceptionListener() {             public void exceptionThrown(Exception e) {                 System.out.println("Exception! :" + e.toString());             }         });         xml.writeObject(getSettings());         xml.close();         fos.close();         fos = new FileOutputStream(path + "\\last-project.project");         xml = new XMLEncoder(fos);         xml.writeObject(getSettings());         xml.close();         fos.close(); 

The file is being created and looks like this:

<?xml version="1.0" encoding="UTF-8"?> <java version="13.0.2" class="java.beans.XMLDecoder">  <object class="preferences.Settings" id="Settings0">   <void property="projectName">    <string>lol</string>   </void>   <void property="universeOut">    <void index="0">     <object class="preferences.UniverseOut"/>    </void>    <void index="1">     <object class="preferences.UniverseOut"/>    </void>   </void>  </object> </java> 

And im pretty confident that this array should contain some stuff, but it isnt saved.

All answers to this question, which has the identifier 61225020

The best answer:

If UniverseOut does not have any non-static fields to be serialized, then there's nothing to be saved, as statics are implicitly transient.

Last questions

how do i remove the switch on my home screen?
how to edit the JS date and time to update atuomatically?
How to utilize data stored in a multidimensional array
Powermockito not mocking URL constructor in URI.toURL() method
Android Bluetooth LE Scanner only scans when phone's Location is turned on in some devices
docker wordpress container can't connect to mysql container
How can I declare a number in java that is more than 64-bits? [duplicate]
Optaplanner solutionClass entityCollectionProperty should never return null error when simple JSON object passed to controller
Anylogic, get the time a pedestrain is in a queue
How do I fix this syntax issue with my .flex file?
Optimizing query in PHP
How to find the highest number of a column and print two columns of that row in R?
Ideas on “Error: Type is referenced as an interface from”?
JCIFS SmbFile.exists() and SmbFile.isDirectory() return false when it exists and I can listFiles()
PHP total order
Laravel booking system design
neural net - undefined column selected
How to indicate y axis does not start from 0 in ggplot?
Fragments in backStack
Spinner how to change the data