Hi all, new here and only been doing java for about a month. I am writing a blackjack game and it’s almost done but I want to use a recordstore for the stats and am having a problem… Here is my code to read/write the RS
private boolean readRS() {
RecordStore rs;
try {
rs = RecordStore.openRecordStore("BlackJack", true);
if (rs.getNumRecords() == 1) {
System.out.println("loading settings");
ByteArrayInputStream buffer = new ByteArrayInputStream(rs.getRecord(1));
DataInputStream stream = new DataInputStream(buffer);
long sv = stream.readLong();
if (sv != this.SETTINGSVERSION) { //previous settings format is diferrent
rs.closeRecordStore();
wins = 0;
losses = 0;
pushes = 0;
blackJacks = 0;
bankRoll = 100000;
soundOn = true;
return writeRS(); //create new format;
//othewise it may cause a crash if we read different format
}
wins = stream.readInt();
losses = stream.readInt();
pushes = stream.readInt();
blackJacks = stream.readInt();
bankRoll = stream.readLong();
soundOn = stream.readBoolean();
rs.closeRecordStore();
System.out.println("Settings read...");
return true;
} else {
wins = 0;
losses = 0;
pushes = 0;
blackJacks = 0;
bankRoll = 100000;
soundOn = true;
rs.closeRecordStore();
return writeRS();
}
} catch (Exception e) {
db(e.toString());
}
return false;
}
public boolean writeRS() {
RecordStore rs;
try {
rs = RecordStore.openRecordStore("BlackJack", true);
ByteArrayOutputStream buffer=new ByteArrayOutputStream();
DataOutputStream stream=new DataOutputStream(buffer);
stream.writeLong(SETTINGSVERSION);
stream.writeInt(wins);
stream.writeInt(losses);
stream.writeInt(pushes);
stream.writeInt(blackJacks);
stream.writeLong(bankRoll);
stream.writeBoolean(soundOn);
//if (rs.getNumRecords() == 1)
rs.setRecord(1, buffer.toByteArray(), 0, buffer.size());
//else
// rs.addRecord(buffer.toByteArray(), 0, buffer.size());
rs.closeRecordStore();
System.out.println("Settings written...");
} catch (Exception e) {
db(e.toString());
return false;
}
return true;
}
I am sure there is some basic thing I am missing but, it has been driving me nuts for 2 days 
Thanks for any help you can give me
Kevin