cancel
Showing results for 
Search instead for 
Did you mean: 

Null Point Exception Error

Former Member
0 Kudos

Hi All

I have to add an input field which will accept email Id from users. This field has to be kept mandatory. I have kept a check on the value entered. If the user does not enter any value, an error message should be displayed. Below is the code that I have written. Whenever, the user keeps this field blank and submits the form, null point exception error is displayed.

Please help how to overcome this problem

email = wdContext.currentContextElement().getEmail_Id();

try{

if (wdContext.currentContextElement().getEmail_Id().equals("") )

{

IWDMessageManager msg = wdThis.wdGetAPI().getComponent().getMessageManager();

msg.reportMessage(IMessageTender_ResignationComp.PERSONAL_EMAIL_ID,new Object[]{"Please enter correct Email Id"},true);

}

else

{

.......

....

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Umang,

Instead of

if (wdContext.currentContextElement().getEmail_Id().equals("") )

try

if (wdContext.currentContextElement().getEmail_Id() == null || wdContext.currentContextElement().getEmail_Id().equals("") )

Regards,

Gopal

Former Member
0 Kudos

hi,

Actually as soon as it finds null, it throws the null pointer exception.....for this you can try the following code:


  String val=wdContext.currentContextElement().getEmail_Id().

      int length=(val==null)?0:val.length();

      if(length==0)

      {

            msg1.raiseMessage(IMessageComp_Message.EMPID,new Object[]{""},true); 

      }

regards,

pinki

Answers (7)

Answers (7)

Former Member
0 Kudos

Hi

Check your Code....

And Debug you app then find where is the error.

Former Member
0 Kudos

hi Umang,

try this,

String E_Mail = wdContext.currentContextElement().getMail();

if(E_Mail.equals(""))
{
   wdComponentAPI.getMessageManager.reportException("Please enter valid EMail Id",true);
}

else
{
   //Process
}

Former Member
0 Kudos

Hi

Put the code as follows:


String email = wdContext.currentContextElement().getEmail_Id();
if( email.equals( "") || ( email == null) || ( email.length == 0))
{
   wdComponentAPI.getMessageManager().reportWarning( "The email field can not be empty!");
}

// checking in three conditions: one for empty second for null value and the last by length of the input email string.

Regards

Vinod V

0 Kudos

hi,

u can initialize the email id attribute to blank in init method

then u can try the following code

if(wdContext.currentContextElement().getAtribute().equalsIgnoreCase(""))

{

print error mesage

}

Former Member
0 Kudos

Hello Umang ,

If the input field is blank, the the chances are node wdContext.currentContextElement()

will be Null. You you cannot get Email id using get Email id, if the node object is null.

Try like this..

if( wdContext.currentContextElement() != null && wdContext.currentContextElement().getEmail_Id().size() == 0){

IWDMessageManager msg = wdThis.wdGetAPI().getComponent().getMessageManager();

msg.reportMessage(IMessageTender_ResignationComp.PERSONAL_EMAIL_ID,new Object[]{"Please enter correct Email Id"},true);

}

Hope this helps.

Former Member
0 Kudos

Hi,

Change the following code to


email = wdContext.currentContextElement().getEmail_Id(); 
try{


if (wdContext.currentContextElement().getEmail_Id().equals("") )
{
IWDMessageManager msg = wdThis.wdGetAPI().getComponent().getMessageManager();
msg.reportMessage(IMessageTender_ResignationComp.PERSONAL_EMAIL_ID,new Object[]{"Please enter correct Email Id"},true);

}

if (wdContext.currentContextElement() != null)
{
    email = wdContext.currentContextElement().getEmail_Id(); 

if ( email.equals("") )
{
IWDMessageManager msg = wdThis.wdGetAPI().getComponent().getMessageManager();
msg.reportMessage(IMessageTender_ResignationComp.PERSONAL_EMAIL_ID,new Object[]{"Please enter correct Email Id"},true);

}
}



Regards

Ayyapparaj

Former Member
0 Kudos

Hi Umang,

if (wdContext.currentContextElement().getEmail_Id().equals("") )

instead of this line try the below code.

if(email == null || email.trim().length() == 0){

IWDMessageManager msg = wdThis.wdGetAPI().getComponent().getMessageManager();

msg.reportMessage(IMessageTender_ResignationComp.PERSONAL_EMAIL_ID,new Object[]{"Please enter correct Email Id"},true);

}

Hope it resolves your problem.

Thanks n Regards,

Jhansi Mirayala