×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    19

    Question validate a Textfield by comparing it to another Textfield

    Hi everyone.
    I am trying to validate a Textfield by comparing it to another Textfield.
    Is this possible? i can successfully validate a single TextField by string, lable, etc. However, when i try to validate it by comparing it to another Textfield, the code errors.

    --------

    peice of code trying to impliment...
    if (userName1.getString().equals(userName2.getString())
    Do Something();

    ---------

    Any help, suggestions, etc will be greatly appreciated.
    Please and thank you.
    Tim.

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: validate a Textfield by comparing it to another Textfield

    try

    if ((userName1.getString()).equals(userName2.getString())) do something();

    it will work.
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

  3. #3
    Registered User
    Join Date
    Aug 2009
    Posts
    19

    Re: validate a Textfield by comparing it to another Textfield

    Thanks heaps for your advice,
    i tried to impliment it in my code but i am still doing something wrong??
    it compiles but when running the midlet at that section it errors with:
    java.lang.NullPointerException
    at J2MEVolt.validateUser(+11)
    at J2MEVolt.commandAction(+77)
    at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
    at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
    at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
    at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
    at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+186)
    at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+57)

    This is how i tried the code:
    public void validateUser() {
    if ((userName.getString()).equals(cuserName.getString()) && (password.getString()).equals(cpassword.getString()) && (txtField.getString()).equals(ctxtField.getString())){
    SafeHouse();
    } else {
    tryAgain();
    }
    }

    Can you see where i am going wrong?
    I was thinking variables??
    Thanks.
    Tim

  4. #4
    Registered User
    Join Date
    Aug 2009
    Posts
    19

    Re: validate a Textfield by comparing it to another Textfield

    all sorted, thanks heaps Amitabh.
    after you pointed out my simple error, it was a matter of having the two pieces of codes in the right place.
    it all works well now. thank you.

Similar Threads

  1. TextField
    By onestep in forum Mobile Java General
    Replies: 6
    Last Post: 2010-05-29, 19:34
  2. getting value from textfield
    By Arunesh in forum Mobile Java General
    Replies: 4
    Last Post: 2009-12-29, 12:21
  3. Replies: 1
    Last Post: 2008-08-28, 21:25
  4. CommandListener on TextField.NUMERIC || TextField.PASSWORD
    By lekkie in forum Mobile Java General
    Replies: 3
    Last Post: 2007-07-09, 13:42
  5. About TextField
    By linbo75 in forum [Archived] Other Programming Discussion 关于其他编程技术的讨论
    Replies: 1
    Last Post: 2003-12-12, 02:15

Posting Permissions

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