Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hai all....

Please help me.

I were write some code to read data store from rms and store it to List in j2me (lstInbox.append(.....)). While I read 1 line index from List, my Form (frmInbox) so always show all of data on rms (if read all of data is ok). And also, I cann't delete it one by one (delete all record is ok).

Can anyone help me, please?

Here my some code:

-----------------Begin:-----------------
public void bacaPesanMasuk() {
        status = 1;
        byte[] bPesan = null;
        frmBaca.deleteAll();
        try {
            re = rs.enumerateRecords(null, this, true);
            while (re.hasNextElement()) {
                int i = re.nextRecordId();
                bPesan = rs.getRecord(i);
                ByteArrayInputStream bais = new ByteArrayInputStream(bPesan);
                DataInputStream dis = new DataInputStream(bais);
                try {
                    String noTelp = dis.readUTF();
                    String pesan = dis.readUTF();
                    byte[] dec = KompressDekompress.decompress(pesan.getBytes());
                    String dekompres = new String(dec);
                    if (smsQ.bBahasaIndonesia == true) {
                        frmBaca.append(dpQ.strTerimaDari[0] + noTelp + "\n");
                        frmBaca.append(dpQ.strTerimaDari[2] + "\n" + pesan + "\n\n");
                        frmBaca.append(dpQ.strTerimaDari[4] + "\n" + dekompres);
                    } else {
                        frmBaca.append(dpQ.strTerimaDari[1] + noTelp + "\n");
                        frmBaca.append(dpQ.strTerimaDari[3] + "\n" + pesan + "\n\n");
                        frmBaca.append(dpQ.strTerimaDari[5] + "\n" + dekompres);
                    }
                } catch (IOException ioe) {
                    ioe.getMessage();
                }
            }
        } catch (InvalidRecordIDException iride) {
            iride.printStackTrace();
        } catch (RecordStoreNotOpenException rsnoe) {
            rsnoe.printStackTrace();
        } catch (RecordStoreException rse) {
            rse.printStackTrace();
        }
        Display.getDisplay(smsQ).setCurrent(frmBaca);
    }



    public void hapusSemuaPesanMasuk() {
        try {
            re = rs.enumerateRecords(null, null, false);
            while (re.hasNextElement()) {
                int i = re.nextRecordId();
                byte[] bScore = rs.getRecord(i);
                ByteArrayInputStream bais = new ByteArrayInputStream(bScore);
                DataInputStream dis = new DataInputStream(bais);
                rs.deleteRecord(i);
                Alert aHapusPesan;
                if (smsQ.bBahasaIndonesia == true) {
                    aHapusPesan = new Alert(dpQ.strLabelCommand_i[3], dpQ.strPesanDihapus[0], null, AlertType.CONFIRMATION);
                } else {
                    aHapusPesan = new Alert(dpQ.strLabelCommand_e[3], dpQ.strPesanDihapus[1], null, AlertType.CONFIRMATION);
                }
                aHapusPesan.setTimeout(2000);
                Display.getDisplay(smsQ).setCurrent(aHapusPesan, this);
            }
            re.rebuild();
        } catch (InvalidRecordIDException iride) {
            iride.printStackTrace();
        } catch (RecordStoreNotOpenException rsnoe) {
            rsnoe.printStackTrace();
        } catch (RecordStoreException rse) {
            rse.printStackTrace();
        }
    }

----------------End of code-------------

Note:
ID En
Baca Read
Pesan Message
Masuk In
Hapus Delete


So sorry for my bad english.
Thanks u so much
Posted
Updated 4-Jan-10 17:56pm
v3

1 solution

You should not delete items when using an enumerator. Use the enumerator to identify the items in the list to be deleted and add them to a temporary list. Then delete the items from the original list that are in the temporary list.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900