Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2001-06-17
6
Medium Priority
?
207 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

715 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