title: read write object in codenameone storage
body: <p>I'm developing a j2me application based on codenameone. I implements some codes and Now I wanna add database to my application. After search a lot I found Storage class of codenameone that simplify database concept in mobile application.</p>
  
  <p>In this appliaction I create a class for each entity (like person, city, ...) and add "read" and "write" method to read and write data.</p>
  
  <p>Some entity classes have 2 or more fields. So I must save and read them with Storage class.</p>
  
  <p>How can I do this?</p>
  
  <p>Here is my sample code:</p>
  
  <pre><code>package com.x.database;
  
  import com.codename1.io.Storage;
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Hashtable;
  import java.util.Iterator;
  
  public class Person {
  
      public Person(){
      }
      public Person(int pID, String pPersonNumber){
          ID = pID;
          PersonNumber = pPersonNumber;
      }
  
      public static String PERSON = "Person";
  
      private Storage store;
      private int ID;
  
      public int getID(){
          return ID;
      }
  
      public void setID(int pID){
          ID = pID;
      }
  
      private String PersonNumber;
  
      public String getPersonNumber(){
          return PersonNumber;
      }
  
      public void setPersonNumber(String pPersonNumber){
          PersonNumber = pPersonNumber;
      }
  
      public int getLastKeyNumber(){
          if(store == null) {
              store = Storage.getInstance();
          }
  
          Hashtable depHash = (Hashtable)store.readObject(PERSON);
          ArrayList&lt;String&gt; keyArray = (ArrayList&lt;String&gt;)depHash.keys();
  
          int i = 0;
          for (Iterator&lt;String&gt; it = keyArray.iterator(); it.hasNext();) {
              int tmp = Integer.parseInt(it.next());
              i = i &lt; tmp ? tmp : i;
          }
  
          return i;
      }
  
      public void write(Person pPerson){
          if(store == null) {
              store = Storage.getInstance();
          }
  
          if(!store.exists(PERSON)) {
              Hashtable depHash = new Hashtable();
              try {
                  depHash.put("0", pPerson);
              } catch (IOException ex) {
                  System.out.println(ex.getMessage());
              }
              store.writeObject(PERSON, depHash);
          }
          else {
              Hashtable depHash = (Hashtable)store.readObject(PERSON);
  
              ArrayList&lt;Person&gt; depArray = (ArrayList&lt;Person&gt;)depHash.keys();
  
              for (Iterator&lt;Person&gt; it = depArray.iterator(); it.hasNext();) {
                  Person tmp = it.next();
  
                  if(!tmp.getPersonNumber().equals(pPerson)) {
                      depHash.put(String.valueOf(getLastKeyNumber()), pPerson.getPersonNumber());
                      store.writeObject(Person depHash);
                  }
              }
          }
      }
  
      public ArrayList&lt;Person&gt; readAll(){
          Storage store = Storage.getInstance();
  
          if(!store.exists(PERSON)) {
              Hashtable depHash = (Hashtable)store.readObject(PERSON);
  
              return (ArrayList&lt;Person&gt;)depHash.elements();
          }
          return new ArrayList&lt;Person&gt;();
      }
  }
  </code></pre>
  
  <p>In this code I have an error on write and read object on Storage.</p>
  
  <p>How can I write one object in Storage and read it again?</p>
  
  <p>Thanks in advance.</p>