on 08-11-2006 6:31 PM
Hi Everybody,
I have a issue with checking the field values entered in a form in WD Java. The values entered in the form are submitted by pressing a button (onAction). Furthermore, the an action is assigned to onEnter of the field. Both, the button (onAction) and the field itself (onEnter), have the same action assigned. First of all we do a check on the values entered in this action. When the field does contain any values, everything works fine, that means the checks (format, length, etc.) are done properly. But there are two situations where I get a NullPointerException and really do not no how to get rid of it:
(1) The cursor is placed in an input field, nothing is entered, and enter key is pressed.
(2) One of the checks was not succesfull and an error message is shown. When the values are now deleted from the field and enter is pressed, the NullPointerExeption is shown again.
The NullPointerException is caused by the following if-statement:
if (strTPersnr.equals(""))
For me it looks like as soon as the cursor was placed in the field, the field value is not blank any more. I also tried to check the length of the field but this does not work either.
I am quite confident I missed something, but I cannot see the wood for the trees anymore. Could someone please help??
Cheers,
Steph
Hi Stephan,
if you get a NullPointerException at this line, then the value of strTPersnr is NULL.
To test against NULL or empty string you can write for example
if (null == strTPersnr || strTPersnr.trim().length() == 0)
{
/* empty */
}
else
{
/* not empty */
}
Another possibility is to create a new DDIC type with length constraint > 0, then the framework performs this check automatically.
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Stephan,
NullPointerException you will get, when you try to compare Null with something. In your code (strTPersnr.equals("")) it gives you NullPointerException.
Before comparing it with something, Check with null.
like,
ex:- String strTPersnr= wdContext.getName();
if(strTPersnr!= null ){
if (strTPersnr.equals(""))
}
Regards,
Sridhar
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
No, unfortunaltely this does not work out neither ... any other ideas?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hai,
try this code
if(strTPersnr.equals("") || strTPersnr==null)
instead of if(strTPersnr.equals(""))
hope it will help
regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.