Hello all,

I have developed one application which import all databases into recordstore. This executes successfully, but the problem comes when I try to Filter my records.
here the code is :

public void itemStateChanged(Item item) {
        
        if (item == choiceGroup_ProductCompany) {
            RecordFilter filter = new RecordFilter() {

            public boolean matches(byte[] candidate) {

                ByteArrayInputStream bis = new ByteArrayInputStream(candidate);
                DataInputStream dis = new DataInputStream(bis);
                String comp;
                int res = 0;
                try {
                    dis.readInt();
                    dis.readUTF();
                    comp=dis.readUTF();
                    String s = choiceGroup_ProductCompany.getString(choiceGroup_ProductCompany.getSelectedIndex());

                    res = (s.toLowerCase()).compareTo(comp.toLowerCase());
                     
                    System.out.println("Pro_Company:" + s.toLowerCase() + "\t" + "Database:" + comp.toLowerCase());

                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (res == 0) {
                    return true;
                }

                return false;
            }
        };
            try {
                choiceGroup_ProductName.deleteAll();

                RecordStore rms = RecordStore.openRecordStore("Product", true);
                RecordEnumeration renum = rms.enumerateRecords(filter, null, false);
                byte[] byt = new byte[2000];
                ByteArrayInputStream bis = new ByteArrayInputStream(byt);
                DataInputStream dis = new DataInputStream(bis);

                while (renum.hasNextElement()) {
                    rms.getRecord(renum.nextRecordId(), byt, 0);
                    dis.readInt();
                    choiceGroup_ProductName.append(dis.readUTF(), null);
                    dis.readUTF();
                    dis.reset();
                    rms.closeRecordStore();
                    dis.close();
                    bis.close();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

        }

    }

and Output is

Pro_Company:dell Database:sony
Pro_Company:dell Database:sony
Pro_Company:dell Database:sony
Pro_Company:dell Database:sony
Pro_Company:dell Database:sony
Pro_Company:dell Database:sony
Pro_Company:dell Database:sony

Here Pro_company is Choicegroup and Database is RecordStore. Here I am expecting Database should keep change. But its not Happening.

Thanking You,
Hakoo Desai.

Recommended Answers

All 2 Replies

Make sure you close any stream you open, JME is very sensitive in this.

Hey,
Thanks for reply. Actually, you are right. Had problem in stream only. My colleague was not resetting it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.