×

Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Jun 2006
    Location
    Israel
    Posts
    1

    IllegalArgumentException on loading application

    Our system needs to recode some numeric values for security purposes. I wrote simply Java midlet that include 2 text fields and 2 commands. WTK KToolBar build package correctly and emulator, of course, work correctly too. But, when I install application on 3100 or 6100 device, it doesn't start! I receive Java/Lang/IllegalArgumenrException message on details .
    I put here my source code. When I was wrong?

    package RonTal.NumCode;

    import javax.microedition.io.*;
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;

    public class JNumCode extends MIDlet implements CommandListener{
    private static JNumCode instance;
    private static final int NUM_SIZE=8;

    /** Soft button for exiting the game. */
    private final Command exitCmd = new Command("Exit", Command.EXIT, 2);

    /** Menu item for changing game levels. */
    private final Command calcCmd = new Command("Recalc", Command.SCREEN, 1);

    /** A text field to keep the first argument. */
    private final TextField t1 = new TextField("Code", "", NUM_SIZE,
    TextField.DECIMAL);

    /** A text field to keep the result of calculation. */
    private final TextField tr = new TextField("Result", "", NUM_SIZE,
    TextField.UNEDITABLE);

    /** An alert to be reused for differemt errors. */
    private final Alert alert = new Alert("Error", "", null, AlertType.ERROR);

    /** Indicates if the application is initialized. */
    private boolean isInitialized = false;

    protected void startApp() {
    if (isInitialized) {
    return;
    }
    Form f = new Form("Keygen");
    f.append(t1);
    f.append(tr);
    f.addCommand(exitCmd);
    f.addCommand(calcCmd);
    f.setCommandListener(this);
    Display.getDisplay(this).setCurrent(f);
    alert.addCommand(new Command("Back", Command.SCREEN, 1));
    isInitialized = true;
    }

    /**
    * Does nothing. Redefinition is required by MIDlet class.
    */
    protected void destroyApp(boolean unconditional) {}

    /**
    * Does nothing. Redefinition is required by MIDlet class.
    */
    protected void pauseApp() {}

    /**
    * Responds to commands issued on CalculatorForm.
    *
    * @param c command object source of action
    * @param d screen object containing actioned item
    */
    public void commandAction(Command c, Displayable d) {
    if (c == exitCmd) {
    destroyApp(false);
    notifyDestroyed();
    return;
    }
    int res = 0;

    try {
    int n = getNumber(t1);
    // here I recalculate numeric value


    } catch (NumberFormatException e) {
    return;
    } catch (ArithmeticException e) {
    alert.setString("Divide by zero.");
    Display.getDisplay(this).setCurrent(alert);
    return;
    }

    /*
    * The resulted string may exceed the text max size.
    * We need to correct last one then.
    */
    String res_str = Integer.toString(res);

    if (res_str.length() > tr.getMaxSize()) {
    tr.setMaxSize(res_str.length());
    }
    tr.setString(res_str);
    }

    private int getNumber(TextField t)
    throws NumberFormatException {
    String s = t.getString();

    if (s.length() == 0) {
    alert.setString("No input");
    Display.getDisplay(this).setCurrent(alert);
    throw new NumberFormatException();
    }
    int n;

    try {
    n = Integer.parseInt(s);
    } catch (NumberFormatException e) {
    alert.setString( "Out of range.");
    Display.getDisplay(this).setCurrent(alert);
    throw e;
    }
    return n;
    }
    }
    Last edited by zimopisec; 2006-06-25 at 19:16.

  2. #2
    Super Contributor
    Join Date
    Dec 2005
    Location
    Europe/Poland/Warsaw
    Posts
    1,697

    Re: IllegalArgumentException on loading application

    hi,

    I could be wrong but for example:
    - devices you noted are MIDP 1.0 (both)
    - TextField.DECIMAL & TextField.UNEDITABLE are from MIDP 2.0

    that could be the reason of that runtime exception,

    just guessing, i'm newbie

    hth,
    regards,
    Peter Blazejewicz

  3. #3
    Regular Contributor
    Join Date
    Jul 2005
    Location
    Omaha, US
    Posts
    129

    Re: IllegalArgumentException on loading application

    Please refer the thread,
    http://discussion.forum.nokia.com/fo...2&page=2&pp=15
    for making it to work with MIDP 1.0 devices.

Similar Threads

  1. Embedded application
    By S.S.Sudhakar in forum Symbian
    Replies: 1
    Last Post: 2005-04-16, 09:36
  2. Replies: 3
    Last Post: 2005-03-24, 10:56
  3. "Responce unknown" while loading application
    By tiex in forum Mobile Java General
    Replies: 0
    Last Post: 2005-02-03, 13:22
  4. Browser and embedded application
    By S.S.Sudhakar in forum Symbian
    Replies: 2
    Last Post: 2005-01-10, 04:47
  5. Replies: 0
    Last Post: 2003-02-03, 08:08

Posting Permissions

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