Solved

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

Posted on 2001-06-17
6
200 Views
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)
     {
          this();
         e2 = inEmp;
         if((String.valueOf(e2.getEmployeeName())==null)) {
                 JlblValidate.setText("Empty Employee Name, please try again");
                 System.out.println(String.valueOf(e2.getEmployeeName()));
         }
         if(String.valueOf(e2.getEmployeePayMethod())==null){
                     JlblValidate.setText("Empty PayMethod, please try again");
                     System.out.println(String.valueOf(e2.getEmployeePayMethod()));
             }
         if(String.valueOf(e2.getEmployeePhone())==null){
                      JlblValidate.setText("Empty Phone Number, please try again");
                      System.out.println(String.valueOf(e2.getEmployeePhone()));
              }
         if(String.valueOf(e2.getEmployeeAddress())==null){
                    JlblValidate.setText("Empty Address, please try again");
                    System.out.println(String.valueOf(e2.getEmployeeAddress()));
            }
         if(String.valueOf(e2.getnDeptID())==null){
                    JlblValidate.setText("Empty Department Number, please try again");
                    System.out.println(String.valueOf(e2.getnDeptID()));
                    }
    }
0
Comment
Question by:dolphin203
  • 2
  • 2
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
Sendoh earned 30 total points
Comment Utility
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..:)

eg.

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

hope it helps...:)

0
 

Author Comment

by:dolphin203
Comment Utility
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.
Registers:
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.
0
 
LVL 3

Expert Comment

by:Sendoh
Comment Utility
its ok...
take ur time...
just post anything if u need help..:)
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
This question remains open, though LOCKED with the proposed answer.

What is your plan in regards to finalizing this question?

Moondancer
Community Support Moderator @ Experts Exchange
0
 

Author Comment

by:dolphin203
Comment Utility
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.
dolphin203
0
 
LVL 1

Expert Comment

by:Moondancer
Comment Utility
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.

Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
The viewer will learn how to implement Singleton Design Pattern in Java.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now