Note that there are some explanatory texts on larger screens.

plurals
  1. POsaving/loading array of objects using java serialization
    text
    copied!<p>I have the following class, which performs some calculations to fill its static arrays.</p> <pre><code>public class Amount implements Serializable{ private static final long serialVersionUID = 8141477444408242243L; public static Amount values1[][] = new Amount[10][30]; public static Amount values2[][] = new Amount[10][30]; public static Amount values3[][] = new Amount[10][30]; double highestValue; double highestAmount; double lowestAmount; double lowestValue; ... } </code></pre> <p>As the calculations take 20 minutes or so, I am looking to store the arrays on file and load the values when the program starts. I am attempting to use the java serialization method and have the following functions</p> <pre><code>public static void loadFile(Amount[][] arr, String filename){ try { FileInputStream fis = new FileInputStream(filename); ObjectInputStream in = new ObjectInputStream(fis); arr = (Amount[][])in.readObject(); in.close(); } catch (Exception e) { System.out.println(e); } } public static void saveFile(Amount[][] arr, String filename){ try { FileOutputStream fos = new FileOutputStream(filename); ObjectOutputStream out = new ObjectOutputStream(fos); out.writeObject(arr); out.flush(); out.close(); } catch (IOException e) { System.out.println(e); } } </code></pre> <p>which I call like this <code>saveFile(values1, "valueOneSaveFile");</code> and <code>loadFile(values1, "valueOneSaveFile");</code></p> <p>I have run the program once, saving all the arrays to various files. The files have been created and look to be around the correct size. When I change my program to call the loadFile functions, the arrays do not appear to initialize correctly. I am getting null pointer exceptions when trying to read a value from the array (which appears to be empty after the load)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload