Help with ERROR

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Tripmaker
    New Member
    • Jun 2007
    • 60

    #1

    Help with ERROR

    Hi!

    In my 'if' statement I'm wanting to say that if the following three textField are not an empty string then it must execute the statements that I've stipulated. The problem is I keep getting an error in my 'if' statement.

    My code looks as follows:

    if(loanField3 != "" && loanField4 != "" && loanField5 != "")

    the error it gives me is 'incomparable types: javax.swing.JTe xtField and java.lang.Strin g
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by Tripmaker
    Hi!

    In my 'if' statement I'm wanting to say that if the following three textField are not an empty string then it must execute the statements that I've stipulated. The problem is I keep getting an error in my 'if' statement.

    My code looks as follows:

    if(loanField3 != "" && loanField4 != "" && loanField5 != "")

    the error it gives me is 'incomparable types: javax.swing.JTe xtField and java.lang.Strin g
    A TextField is not a String, that's why your compiler keeps whining. You can
    retrieve a String from a TextField by asking for it: TextField.getTe xt()
    and you can compare those Strings then but you can't compare Strings for
    equality with the '==' operator or the '!=' operator, i.e. you have to use the
    String.equals() method for that purpose.

    If you just want to check whether or not the Strings are empty you could use
    the String.length() operator also.

    kind regards,

    Jos

    Comment

    • Tripmaker
      New Member
      • Jun 2007
      • 60

      #3
      Originally posted by JosAH
      A TextField is not a String, that's why your compiler keeps whining. You can
      retrieve a String from a TextField by asking for it: TextField.getTe xt()
      and you can compare those Strings then but you can't compare Strings for
      equality with the '==' operator or the '!=' operator, i.e. you have to use the
      String.equals() method for that purpose.

      If you just want to check whether or not the Strings are empty you could use
      the String.length() operator also.

      kind regards,

      Jos

      Thanks. I'll try that.

      Comment

      Working...