   MIDP Record store help
  Hey I'm new to using record stores in j2me and I've looked over various tutorials but I cant figure out how to store and retrieve data.I have an array of boolean values and an array of int values I'd like to store and retrieve how can I do that?-Regards Namingway   
  To store the values, you open a record store, and then write the values to a record (you'll typically want to then close the record store). To retrieve them, you open the same record store, and then read the values from the same record (and again, probably close it again - although you might design something that involves leaving it open).What part exactly are you having trouble with? "storing and retrieving data" is basically all that record stores *do*, so "looking over various tutorials" should be more than enough of a guide.   ;  I'm having trouble actually coding it, I'm not sure on the code to store data in the record store.   ;  You need to convert the data to a byte array before adding it to the record store.Once you have converted the data to a byte array you can add it to the record store using.RecordStore.addRecord(data, 0, datalength);To convert your arrays into byte arrays use a bytearrayoutputstream or write your own conversion methods.   ;  I've trying a few things and I've noticed the record store never seems to get created that or, my reading code cant find it.//record outputtry   {  RecordStore rs = RecordStore.openRecordStore("save", true);  ByteArrayOutputStream baos = new ByteArrayOutputStream();  DataOutputStream out = new DataOutputStream(baos);  try   { for(int i = 0; i < GameData.Switch.length; i++) {out.writeBoolean(GameData.Switch); } out.close();  }  catch (IOException ioe)   { System.out.println(ioe); ioe.printStackTrace();  }  byte[] b = baos.toByteArray();  rs.addRecord(b, 0, b.length);    rs.closeRecordStore();   }   catch(RecordStoreException rse)    {  rse.printStackTrace();   }record inputtry{    RecordStore rs = RecordStore.openRecordStore("save", false);    byte[] data = rs.getRecord(0);    DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));    try{   //for(int i = 0; i < GameData.Switch.length; i++)   //{   //   GameData.Switch = in.readBoolean();   //}   System.out.println(in.readUTF());    }    catch (IOException ioe){   System.out.println(ioe);   ioe.printStackTrace();    }    rs.closeRecordStore();}catch(RecordStoreException rse) {    rse.printStackTrace();}Is there something I did wrong or left out?   ;  You'll laugh, but... record store IDs start at 1, not 0. I still have no idea why they did that. :) You are supposed to have been able to figure this out by observing that the outer catch on the read method gets triggered by an InvalidRecordIDException (which extends RecordStoreException), and then going to check the documentation. Do you have any experience with reading stack traces?(Also, readUTF() isn't going to work very well on data that was written with writeBoolean(). writeBoolean() writes a byte for each boolean value, either 1 or 0... readUTF() expects the data to be prefaced with a 2-byte length count, and interprets the rest of the data as UTF-8, so you can imagine how that will mess up.)   ;  Its working now :) as for the writeUTF() I'd forgot to comment it out and uncomment the boolean. I can't say I have any experience with stack traces I'll look it up. One other thing when the phone emulator is closed are the record supposed to be deleted? I've noticed when I close the emulator the record can't be found. Thanks for the help!   