未能一对一读取和删除记录存储 [英] Failed to Read and delete recordstore one by one

查看:100
本文介绍了未能一对一读取和删除记录存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好....

请帮帮我.

我正在编写一些代码来从rms读取数据存储,并将其存储到j2me中的List(lstInbox.append(.....)).当我从列表中读取1行索引时,我的窗体(frmInbox)始终以rms显示所有数据(如果可以读取所有数据,则可以).而且,我无法将其一一删除(删除所有记录都可以).

有人可以帮我吗?

这是我的一些代码:

-----------------开始:-----------------

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();
        }
    }


----------------代码结尾-------------

注意:
ID En
Baca阅读
Pesan留言
Masuk In
Hapus Delete


非常抱歉我的英语不好.
非常感谢您


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

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


So sorry for my bad english.
Thanks u so much

推荐答案

使用枚举器时不应删除项目.使用枚举器标识列表中要删除的项目,并将其添加到临时列表中.然后从原始列表中删除临时列表中的项目.
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.


这篇关于未能一对一读取和删除记录存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆