Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

Posted on 2001-06-17
Medium Priority
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 90 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 it...it 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..:)
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month13 days, 7 hours left to enroll

578 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