000
23.05.2009, 09:42
RikkuZooo
|
Könnte mir jemand helfen das das RMS automatich speichert?
Habe mich mi denn RMS noch nicht auseinander gesetzt.
import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import javax.microedition.midlet.MIDlet; import javax.microedition.rms.*;
public class AirChina extends MIDlet { public AirChina() { display = Display.getDisplay(this); canvas = new PaintCanvas(this); }
protected void startApp() { RecordStore rs = null; byte[] name = null; boolean existingOrNot = false; boolean OK = true;
existingOrNot = existing("aRS");
if (existingOrNot) { try { rs = RecordStore.openRecordStore("aRS", false); } catch (Exception e) { OK = false; } finally { if (OK) { } else { } } } else { try { rs = RecordStore.openRecordStore("aRS", true); } catch (Exception e) { OK = false; } finally { if (OK) { } else { } } }
if (OK) { try { name = ("Save").getBytes(); rs.addRecord(name, 0, name.length); } catch (Exception e) { } try { rs.deleteRecord(1); } catch (InvalidRecordIDException e) { // try { // } catch (RecordStoreNotOpenException rse) { // } } catch (RecordStoreException e) { } finally { try { rs.closeRecordStore(); } catch (Exception e) { } } }
display.setCurrent(canvas); }
public boolean existing(String recordStoreName) { boolean existingOrNot = false; RecordStore rs = null; if (recordStoreName.length() > 32) return false; try { rs = RecordStore.openRecordStore(recordStoreName, false); } catch (RecordStoreNotFoundException e) { existingOrNot = false; } catch (Exception e) { } finally { try { rs.closeRecordStore(); } catch (Exception e) { } } return existingOrNot; }
protected void pauseApp() { }
protected void destroyApp(boolean flag) { display.setCurrent((Displayable)null); canvas.destroy(); notifyDestroyed(); }
Display display; PaintCanvas canvas; }
--
AirChina Mobile
|
|
Profil || Suche
|
001
23.05.2009, 11:01
hausi
|
Deine existing(String) ist definitiv noch falsch, da fehlt ein return true; nach rs = ...; Das Speichern im RS sieht bei mir so aus:
try { RecordStore.deleteRecordStore(STORE_NAME); } catch (RecordStoreNotFoundException e) { } RecordStore rs = RecordStore.openRecordStore(STORE_NAME, true); try { byte[] data = os.toByteArray(); rs.addRecord(data, 0, data.length); } finally { rs.closeRecordStore(); }
Du löschst deinen Eintrag allerdings nachdem du ihn hinzugefügt hast direkt wieder.
Falls du willst, kann ich dir gerne auch meinen kompletten Code zukommen lassen. Edit: Dann einfach eine PN mit Mail-Adresse schicken, da der Code zu lange fürs Forum ist.
--
Dieser Beitrag wurde am 23.05.2009 um 11:03 von hausi bearbeitet.
|
|
Profil || Suche
|