checkout the code running perfectly. By the way what error r u facing? Please mention that. Might be the problem is recId.
When u send recId = 0 then program runs ok but when u send RecId = value other than 0 or 1 like 2 or 3 then u are facing problem coz recordId is not exist when u set the record at recId = 2 or 3. Its just my guess. Please mention the exception comes if any.
Code:
private void addRecord(int recId) {
// Add records to recordStore
ByteArrayOutputStream bout = new ByteArrayOutputStream();
DataOutputStream dout = new DataOutputStream(bout);
try {
dout.writeUTF("Jitendra");
dout.writeUTF("Agarwal");
dout.close();
byte[] data = bout.toByteArray();
RecordStore store = RecordStore.openRecordStore("NoteLibrary", true);
if (recId == 0) {
recId = store.addRecord(data, 0, data.length);
} else {
store.setRecord(recId, data, 0, data.length);
}
store.closeRecordStore();
} catch (RecordStoreNotOpenException e) {
e.printStackTrace();
} catch (RecordStoreFullException e) {
e.printStackTrace();
} catch (RecordStoreException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}