0

Hello Friends,

I have created application which can be work In Online Mode(GPRS) and Offline Store(Recordstore). Its working fine in default configuration and touch configuration. But its not working on QWERTYDevice(In emulator as well as On real Mobile Device(Nokia X2-01)).

In Emulator I am getting This Error :

java.lang.NegativeArraySizeException
        at javax.microedition.rms.RecordStore.getRecord(RecordStore.java:920)
        at javax.microedition.rms.RecordEnumerationImpl.reFilterSort(RecordEnumerationImpl.java:573)
        at javax.microedition.rms.RecordEnumerationImpl.rebuild(RecordEnumerationImpl.java:259)
        at javax.microedition.rms.RecordEnumerationImpl.<init>(RecordEnumerationImpl.java:85)
        at javax.microedition.rms.RecordStore.enumerateRecords(RecordStore.java:1092)
        at pkg.com.log.ONOFFAPP1.search_ModelAll(ONOFFAPP1.java:576)
        at pkg.com.log.ONOFFAPP1.commandAction(ONOFFAPP1.java:357)
        at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(Display.java:2093)
        at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(Display.java:2929)
        at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(DefaultEventHandler.java:297)
        at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(AutomatedEventHandler.java:667)
        at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(DefaultEventHandler.java:711)
        at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(DefaultEventHandler.java:608)

And Code is :

public void search_ModelAll() {
        choiceGroup_Model.deleteAll();

        byte[] byt = new byte[5000];
        ByteArrayInputStream bis = new ByteArrayInputStream(byt);
        DataInputStream dis = new DataInputStream(bis);
        //ID, Product, Company
        try {
            RecordStore rms_comp = RecordStore.openRecordStore("Model", false);
            RecordEnumeration renum = rms_comp.enumerateRecords(new RecordFilter() {// At this point its going to catch block
                public boolean matches(byte[] candidate) {
                    String cur_comp = choiceGroup_Company.getString(choiceGroup_Company.getSelectedIndex());
                    String comp, cur_pro = textField.getString().toLowerCase();
                    DataInputStream dis = new DataInputStream(new ByteArrayInputStream(candidate));
                    try {
                        dis.readInt();//ID
                        dis.readUTF();//Model
                        String pro = dis.readUTF().toLowerCase();//Product
                        comp = dis.readUTF();//Company
                        dis.readUTF();//Qty
                        dis.readUTF();//Price

                        if (comp.toLowerCase().indexOf(cur_comp.toLowerCase()) == 0) {
                            if (pro.indexOf(cur_pro) == 0) {
                                return true;
                            }
                        } else {
                            return false;
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return false;
                }
            }, null, midletPaused);

            renum.hasNextElement();
            rms_comp.getRecord(renum.nextRecordId(), byt, 0);
            dis.readInt();
            choiceGroup_Model.append(dis.readUTF(), null);
            dis.readUTF();
            dis.readUTF();
            txt_Qty.setString(String.valueOf(dis.readInt()));
            txt_Price.setString(dis.readUTF());

            bis.reset();

            while (renum.hasNextElement()) {
                rms_comp.getRecord(renum.nextRecordId(), byt, 0);
                dis.readInt();
                choiceGroup_Model.append(dis.readUTF(), null);
                dis.readUTF();
                dis.readUTF();
                dis.readInt();
                dis.readUTF();

                bis.reset();
            }
            rms_comp.closeRecordStore();
            bis.close();
            dis.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

And in Real Device I am getting, "ARRAY INDEX OIT OF BOUNDS JAVA/LANG/ARRAYINDEXOUTOFBOUNDS EXCEPTION". This error I am getting when I try to run Offline mode midlet but Oniline midlet is working fine.

Thanking You,
Hakoo S Desai.

Edited by peter_budo: Replacing [tex] with [color=red], sorry but tex is difficult to read

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Hakoo
0

This is an extremely important/useful/practical post. Hope someone answers this....it seems Mobile development in Daniweb isn't as renowned as the other developing forums.

0

@Usmaan that would be down to the fact that most questions in this section are answered only by me. However recently I do not have so much time, plus JME is not so "cool" and popular as it use to be. My guess here would be failure to check if given record store exists before attempting to access it

0

Hello,

I found the way to solve it. Here, the thing is JME can run on any Java-Enabled Device. Not like Iphone or Android that want specified hardware.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.