Note that there are some explanatory texts on larger screens.

plurals
  1. POWriteAbortedException Java
    primarykey
    data
    text
    <p>I have the following method. The purpose of this method is to retrieve from the cache the stored arraylist.</p> <pre><code> public ArrayList&lt;T&gt; read_arraylist_from_cache(File name){ FileInputStream fis; ArrayList&lt;T&gt; returnlist = null; try { fis = new FileInputStream(name); ObjectInputStream ois = new ObjectInputStream(fis); //here I take the exception returnlist = (ArrayList&lt;T&gt;) ois.readObject(); ois.close(); } catch (Exception e) { Log.d("Cannot retrieve the arraylist from the cache", "Cannot retrieve the arraylist from the cache", e); e.getStackTrace(); } return returnlist; } </code></pre> <p>However when I'm trying to cast to ArrayList I'm taking a WriteAbortedException. The ArrayList that I'm passing to aforementioned class is the following one:</p> <pre><code> ArrayList &lt;Product&gt; </code></pre> <p>Where the product pojo is:</p> <pre><code> public class Products implements Serializable{ @JsonProperty private String prodnum; @JsonProperty private String brand; //get,set } </code></pre> <p>The method that I'm using in order to store the arraylist to the cache is the following</p> <pre><code> public void write_to_byte_array(ArrayList&lt;T&gt; list,File file){ // write to byte array FileOutputStream fos = null; try { fos = new FileOutputStream(file); } catch (FileNotFoundException e1) { Log.d("file not found", "file not found", e1); } ObjectOutputStream oos = null; try { oos = new ObjectOutputStream(fos); } catch (Exception e1) { Log.d("Create ObjectOutputStream object", "Create ObjectOutputStream object", e1); } try { oos.writeObject(list); } catch (IOException e1) { Log.d("Write ObjectOutputStream object to file", "Write ObjectOutputStream object to file", e1); } try { oos.close(); } catch (IOException e1) { Log.d("Close the connection with the file", "Close the connection with the file", e1); } } </code></pre> <p>The arratList list that I pass to the aforementioned method is an </p> <pre><code> ArrayList&lt;Products&gt; </code></pre> <p>again, and the file is the same as the file that I wrote before. However I can't understand what I'm doing wrong. Can anyone help me?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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