Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2001-06-17
6
Medium Priority
?
208 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 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..:)

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
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.
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
ID: 6200810
its ok...
take ur time...
just post anything if u need help..:)
0
Industry Leaders: 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!

 
LVL 1

Expert Comment

by:Moondancer
ID: 6711050
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
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.
dolphin203
0
 
LVL 1

Expert Comment

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

Moondancer
Community Support Moderator @ Experts Exchange
0

Featured Post

Industry Leaders: 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!

Question has a verified solution.

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

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…
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…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

972 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