Validation of null or "" in a textfield is not working with "==" operator

Posted on 2001-06-17
Last Modified: 2010-03-31
My program compiles fine and goes thru the motions, but will not detect a null textfield. I've tried everything from nulls to spaces in quantity to no avail. Any help would be appreciated. The validation code I am using is as follows; note;(the prints are for debug purposes and show the "if" statement is working if I change the "==" to "!=")
public JdlgValidate(Employee inEmp)
         e2 = inEmp;
         if((String.valueOf(e2.getEmployeeName())==null)) {
                 JlblValidate.setText("Empty Employee Name, please try again");
                     JlblValidate.setText("Empty PayMethod, please try again");
                      JlblValidate.setText("Empty Phone Number, please try again");
                    JlblValidate.setText("Empty Address, please try again");
                    JlblValidate.setText("Empty Department Number, please try again");
Question by:dolphin203
  • 2
  • 2
  • 2

Accepted Solution

Sendoh earned 30 total points
ID: 6200670
hi !
first of all, check if the string object is null....
then if not, check if the string with length 0....
think this will cover most of the cases u mentioned..:)


if (txtField.getText()!=null && 
    //process code here
    System.out.println("txtField cannot be null or empty")

hope it helps...:)


Author Comment

ID: 6200775
Sendoh, thanks for the response. I've discovered that a textfield on a form will never return a null. That's why my method is not working. I used your suggestion of trim().length() ==0 and it compiles fine. However, Now I'm getting an eligal operation error when I select a textfield for entry.
JAVAW caused an invalid page fault in
module <unknown> at 0084:1f909400.
EAX=05fd06b4 CS=0167 EIP=1f909400 EFLGS=00010297
EBX=05fd1334 SS=016f ESP=04ddf650 EBP=04ddf670
ECX=05fd0e78 DS=016f ESI=05fd0e78 FS=4bd7
EDX=05fd0e78 ES=016f EDI=00000000 GS=0000
Bytes at CS:EIP:
I'm running Visual Cafe 4.1a. I don't think the change has anything to do with may have something to do with the amount of memory in my laptop...I have 96meg, will have to check it out and get back to you. I think your fix will take care of my problem if I get by this.

Expert Comment

ID: 6200810
its ok...
take ur time...
just post anything if u need help..:)
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.


Expert Comment

ID: 6711050
This question remains open, though LOCKED with the proposed answer.

What is your plan in regards to finalizing this question?

Community Support Moderator @ Experts Exchange

Author Comment

ID: 6712769
Accepted Sendoh's response, although I now have a different problem when using his code, I believe this is related to my laptop and Visual Cafe'. I'm using the method described in my original question to resolve my problem, but I believe Sunduh's code to be accurate. My original thought was to reject and delete the question, (which I thought I had done), but I don't believe that would be fair to Sundah. Therefore, I'm awarding him the points.
My appologies for not realizing this question was still open.

Expert Comment

ID: 6714496
Thank you for returning and updating/finalize this.  Since EASY questions typically begin at a point value of 50, it seems fair to award points here for the information offered.  The expert last stated that he (or she) was waiting for you to give some more information, but that didn't follow.  You'll find that staying current with your questions, and providing timely feedback will help you achieve the "A" quality results that everyone here strives to obtain, and more quickly.

If you choose to open another question, and it related to this, just include the link to this so that a trail is maintained on progress to date.  That should prove helpful.

Question that are "medium" in terms of difficulty are typically 100 points, those requiring more complex information range from 200 to 300 points.  That should also help you in deciding point values to draw attention and get results.  The HELP DESK on the left is quite helpful.

Community Support Moderator @ Experts Exchange

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question