Results 1 to 2 of 2
  1. #1
    romina is offline Member
    Join Date
    Jul 2007
    Posts
    26
    Rep Power
    0

    Default Problem with JTextFields not null

    I have a some JTextFields that I want to verify the contents of. IF the field is left blank it will add a message to my error window ELSE it will preform another check.

    The OTHER check works fine, but it never seems to give me the proper error message if the field is blank, it immediatly goes to the ELSE statement.

    If I do a
    Java Code:
    System.out.println(variableName);
    , the variable appears to be NULL.

    Java Code:
    //animation delay is the name of the textfield
            animationDelay = this.animationDelay.getText();
    
            /* check if animation delay was left blank */
            if (animationDelay == null ||
                    animationDelay == ""){
                errMsg.add("Please enter disk Animation Delay");
            } else {
                /* check if the input given is valid */
                try {
                    /* parse the animation delay entered into an integer */
                    int animationDelayInt = Integer.parseInt(animationDelay);
                    /* check range of animation delay */
                    if (animationDelayInt < MIN_ANIMATION_DELAY){
                        errMsg.add("Animation Delay must be greater than 0");
                    } else if (animationDelayInt > MAX_ANIMATION_DELAY){
                        errMsg.add("Animation Delay must be less than " + MAX_ANIMATION_DELAY);
                    }
                } catch (NumberFormatException ex) {
                    errMsg.add("Animation Delay must be a Number");
                }
    if I manually set animationDelay = null; the proper error message is displayed.

    why is the blank field not being detected as null?
    Is there an invisible character that blank JTextFields insert in order to ruin my life?

    Thanks

  2. #2
    trill is offline Member
    Join Date
    Jul 2007
    Posts
    40
    Rep Power
    0

    Default

    Null is not the same as empty-- null means undefined, empty means defined and, well, empty

    So try if (animationDelay == "") instead, see if that works for you.

    Greetings.

Similar Threads

  1. NULL Value Of parameters
    By riders in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-14-2008, 03:29 PM
  2. Comparing null problem
    By thirdy_veritech in forum New To Java
    Replies: 2
    Last Post: 02-06-2008, 09:46 AM
  3. What is NULL
    By bugger in forum New To Java
    Replies: 1
    Last Post: 01-09-2008, 05:55 PM
  4. parameters=null
    By mary in forum Java Servlet
    Replies: 1
    Last Post: 07-13-2007, 05:29 PM
  5. JTextFields with username & password.
    By Eric in forum AWT / Swing
    Replies: 2
    Last Post: 07-02-2007, 12:41 AM

Posting Permissions

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