Results 1 to 4 of 4
  1. #1
    ryanlcc is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default The midlet cannot search...

    The midlet compliled successfully..
    Once run,
    I enter 3 different records...
    then after when I 'VIEW' for example I enter recordID: 1..
    by right, all the details about recordId : 1 would be listed out...somehow, this error pops up.
    java.lang.IllegalArgumentException



    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.rms.*;
    
    /**
     * @author RyanLCC
     */
    public class cdSeller extends MIDlet implements CommandListener{
    
        private Display display;
        private Form form;
        private Command add, view, update, delete, exit;
        private TextField rcdId, title, quantity, price, profit, director, publish, actors;
        private RecordStore rs;
        private Alert alert = new Alert("New Data Added !!!");
        private Alert alert1 = new Alert("Database Upated!!!");
        private Alert alert2 = new Alert("Record Deleted!!!");
        private Alert alert3 = new Alert("Looking Data!!!");
    
        public cdSeller()throws RecordStoreException{
    
        display = Display.getDisplay(this);
        exit = new Command("Exit", Command.EXIT, 1);
        add = new Command("Add",Command.SCREEN,2);
        update = new Command("Update",Command.SCREEN,2);
        delete = new Command("Delete",Command.SCREEN,2);
        view = new Command("View",Command.SCREEN,2);
    
        rcdId= new TextField("Record ID     :","",5,TextField.NUMERIC);
        title= new TextField("Title         :","",11,TextField.ANY);
        quantity= new TextField("Quantity   :","",8,TextField.NUMERIC);
        price= new TextField("Retail price  :","",8,TextField.ANY);
        profit= new TextField("Profit margin:","",8,TextField.ANY);
        director= new TextField("Director   :","",11,TextField.ANY);
        publish= new TextField("Publisher   :","",11,TextField.ANY);
        actors= new TextField("Actors       :","",11,TextField.ANY);
    
        rs = RecordStore.openRecordStore("My CD Datbase Directory", true);
        form = new Form("My CD Database");
    
        form.append(rcdId);
        form.append(title);
        form.append(quantity);
        form.append(price);
        form.append(profit);
        form.append(director);
        form.append(publish);
        form.append(actors);
    
        form.addCommand(exit);
        form.addCommand(add);
        form.addCommand(update);
        form.addCommand(delete);
        form.addCommand(view);
        form.setCommandListener(this);
        }
        public void startApp() {
            display.setCurrent(form);
        }
    
        public void pauseApp() {
        }
    
        public void destroyApp(boolean unconditional) {
            try {
                rs.closeRecordStore();
            } catch (RecordStoreException ex) {
                ex.printStackTrace();
            }
        }
    
        public void commandAction(Command c, Displayable d) {
    
            alert.setTimeout(3000);
            alert1.setTimeout(3000);
            String str;
            byte bytes[];
            int recordID;
            
            try{
                if(c==add){
                    str = title.getString()+":"+quantity.getString()+
                          ":"+price.getString()+":" +profit.getString()+
                          ":"+director.getString()+":"+publish.getString()+
                          ":"+actors.getString();
                    bytes=str.getBytes();
                    recordID = rs.addRecord(bytes, 0, bytes.length);
    
                    System.out.println("Record of ID:"+recordID+" is added");
                    Display.getDisplay(this).setCurrent(alert);
                
                }else if(c==update){
                    recordID = Integer.parseInt(rcdId.getString());
                    str = title.getString()+":"+quantity.getString()+
                          ":"+price.getString()+":" +profit.getString()+
                          ":"+director.getString()+":"+publish.getString()+
                          ":"+actors.getString();
                    bytes=str.getBytes();
                    rs.setRecord(recordID, bytes, 0, bytes.length);
                    Display.getDisplay(this).setCurrent(alert1);
    
                }else if(c == delete){
                    recordID = Integer.parseInt(rcdId.getString());
                    rs.deleteRecord(recordID);
                    Display.getDisplay(this).setCurrent(alert2);
                
                }else if(c == view ){
                    recordID = Integer.parseInt(rcdId.getString());
                    bytes = new byte[rs.getRecordSize(recordID)];
                    rs.getRecord(recordID,bytes,0);
                    String str1 = new String(bytes);
                    int index = str1.indexOf(":");
                    title.setString(str1.substring(0));
                    quantity.setString(str1.substring(1));
                    price.setString(str1.substring(2));
                    profit.setString(str1.substring(3));
                    director.setString(str1.substring(4));
                    publish.setString(str1.substring(5));
                    actors.setString(str1.substring(6));
    
            }else if( c == exit){
                destroyApp(true);
                notifyDestroyed();
            }
               
        }catch(Exception e){
            e.printStackTrace();
        }
    
        }
    }
    ERROR MESSAGE:
    java.lang.IllegalArgumentException
    at javax.microedition.lcdui.TextField.setCharsImpl(), bci=79
    at javax.microedition.lcdui.TextField.setString(), bci=37
    at cdSeller.commandAction(cdSeller.java:118)
    at javax.microedition.lcdui.Display$ChameleonTunnel.c allScreenListener(), bci=46
    at com.sun.midp.chameleon.layers.SoftButtonLayer.proc essCommand(), bci=74
    at com.sun.midp.chameleon.layers.SoftButtonLayer.comm andSelected(), bci=11
    at com.sun.midp.chameleon.layers.MenuLayer.pointerInp ut(), bci=170
    at com.sun.midp.chameleon.CWindow.pointerInput(), bci=76
    at javax.microedition.lcdui.Display$DisplayEventConsu merImpl.handlePointerEvent(), bci=19
    at com.sun.midp.lcdui.DisplayEventListener.process(), bci=296
    at com.sun.midp.events.EventQueue.run(), bci=179
    at java.lang.Thread.run(Thread.java:619)
    Last edited by ryanlcc; 08-01-2010 at 05:49 AM. Reason: code tags added

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    Do you have any environment where you can get the stack trace that would show what statement in the code that the error occurs on?
    If you have the stack trace, please post it.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    @OP, please use code tags next time posting here. Unformated codes are really hard to read. If you don't know how to do that check on my forum signature.

    And also post the complete error message next time, it's really helpful to comment on you.
    Last edited by Eranga; 08-01-2010 at 05:14 AM. Reason: added more

  4. #4
    ryanlcc is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default

    I have updated my post together with the error messages.....I am still thinking how come such error can exist...

Similar Threads

  1. Binary search tree search method
    By chopo1980 in forum New To Java
    Replies: 2
    Last Post: 12-10-2009, 01:42 AM
  2. sms midlet
    By Poonam in forum CLDC and MIDP
    Replies: 3
    Last Post: 11-25-2009, 02:47 PM
  3. Replies: 0
    Last Post: 10-29-2009, 09:28 AM
  4. Replies: 5
    Last Post: 08-26-2008, 03:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •