title: How to store an ArrayList of custom objects using the Internal Storage?
body: <p>I want to store the ArrayList of custom objects called WordList using the Internal Storage.</p>
  
  <p>Here's my code:</p>
  
  <pre><code>@SuppressWarnings("serial")
  public class WordList extends MainActivity implements Serializable {
  
  public String name;
  public ArrayList&lt;String&gt; wordarray;
  public ArrayList&lt;String&gt; definitionarray;
  
  public WordList(String newName)
  {
      this.name = newName;
      this.wordarray = new ArrayList&lt;String&gt;();
      this.definitionarray = new ArrayList&lt;String&gt;();
  }
  
  public String getName()
  {
      return name;
  }
  
  private void writeObject(ObjectOutputStream out) throws IOException {
      out.writeUTF(name);
      out.writeObject(wordarray);
      out.writeObject(definitionarray);
  }
  
  private void readObject(ObjectInputStream in) throws IOException,
          ClassNotFoundException {
      name = in.readUTF();
      wordarray = (ArrayList&lt;String&gt;) in.readObject();
      definitionarray = (ArrayList&lt;String&gt;) in.readObject();
  }  
  }
  </code></pre>
  
  <p>And here's the main activity:</p>
  
  <pre><code>    public class MainActivity extends Activity {
  private EditText text;
  private ArrayList&lt;WordList&gt; lists = new ArrayList&lt;WordList&gt;();
  private TextView textview;
  FileOutputStream fos;
  String filePath;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      text = (EditText) findViewById(R.id.editText1);
      textview = (TextView) findViewById(R.id.test);
      filePath = getApplicationContext().getFilesDir().getPath().toString() + ".fileName.txt";
  }
  
  
  public void onClick(View view) throws FileNotFoundException {
      switch (view.getId()) {
      case R.id.addtoarray:
          String input = text.getText().toString();
          WordList list = new WordList(input);
          lists.add(list);
          break;
      case R.id.save:
          try {
              File f = new File(filePath);
              FileOutputStream fos = new FileOutputStream(f, true);
              ObjectOutputStream oos = new ObjectOutputStream(fos);
              Toast.makeText(getApplicationContext(), "Wrote " + String.valueOf(lists.size() + "objects to file!"), Toast.LENGTH_LONG).show();
              oos.writeInt(lists.size());
              for(int i=0; i&lt;lists.size(); i++)
              {
                  oos.writeObject(lists.get(i));
              }
              oos.close();
              fos.close();
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          } catch (IOException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
          break;
      case R.id.load:
          File saveFile = new File(filePath);
          if (saveFile.exists())
          {
              Toast.makeText(getApplicationContext(), "File found!",
                      Toast.LENGTH_SHORT).show(); 
          try {
              FileInputStream fis = new FileInputStream(saveFile);
              ObjectInputStream ois = new ObjectInputStream(fis);
              int num = ois.readInt();
              for(int i = 0; i&lt;num; i++)
              {
                  WordList o = (WordList) ois.readObject();
                  lists.add(o);
              }
              fis.close();
              ois.close();
          } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (StreamCorruptedException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
      } else {
          Toast.makeText(getApplicationContext(), "File not found!",
                Toast.LENGTH_SHORT).show();
      }
          textview.setText(lists.get(0).getName());
          break;
      }
  }
  </code></pre>
  
  <p>Regarding Toasts, the objects are saved, but the app have problems with reading them. Could someone please tell me what am I doing wrong here?</p>