954,529 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

J2ME : RecordStore Filtering Problem

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.

Hakoo
Junior Poster
117 posts since Mar 2010
Reputation Points: 24
Solved Threads: 5
 

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

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

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

Hakoo
Junior Poster
117 posts since Mar 2010
Reputation Points: 24
Solved Threads: 5
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: