cancel
Showing results for 
Search instead for 
Did you mean: 

NullPointer exception

Former Member
0 Kudos

Hi,

I have a inputfiled with date type. If i enter any number without any format. I should get message like " Enter the value in the format 25/11/1987" . But that message is displaying only some time. But some time it display error message saying that nullpointer exception.

I should get that message all the time when i enter wrong date format value.

Regards,

H.V.Swathi

Accepted Solutions (0)

Answers (4)

Answers (4)

former_member40425
Contributor
0 Kudos

Where ever you are trying to use method compareTo and getYear from any date, that date should not be null.

Regards,

Rohit

former_member201361
Active Contributor
0 Kudos

Hi Swathi,

Null Pointer Exception is nothing to do with input Field with Date attribute. please check whether the cardinality of the node EmpDetail. the null pointer exception might be coz of empDetailElement or the date object being null .from the error trace , u will be able to find the actual line from where the exception is being raised. if possible post the error trace.

Thanks and Regards

former_member201361
Active Contributor
0 Kudos

Hi Swathi,

I have a inputfiled with date type. If i enter any number without any format. I should get message like " Enter the value in the format 25/11/1987" . But that message is displaying only some time. But some time it display error message saying that nullpointer exception.

Can u post the complete Error trace ie Null Pointer Exception ?

Thanks and Regards

Former Member
0 Kudos
try{    
		Date dateb=wdContext.currentEmpDetailElement().getZem_Dob();
		Date datej=wdContext.currentEmpDetailElement().getZem_Doj();
		Date datec=wdContext.currentEmpDetailElement().getZem_Doc();
		     	
	if((wdContext.currentEmpDetailElement().getZem_Dom()) != null)
	{
		if((wdContext.currentEmpDetailElement().getZem_Dom()).compareTo(dateb) > 0)
		{
	if((datej.getYear()-dateb.getYear()) >= 18 && datej.compareTo(datec) >= 0 ){
	if(wdThis.emailTest(wdContext.currentEmpDetailElement().getZem_Mail())==true )
	{
	if(wdThis.validphoneno(wdContext.currentEmpDetailElement().getZem_Phone())==true)
	{
 wdThis.Save();
	}
	  else
	  {
		String errorMessage = "phone no is not valid  !";
				  IWDEventHandlerInfo windowHandler = wdControllerAPI.getViewInfo().getViewController().findInEventHandlers("OK");
				  IWDConfirmationDialog windowDialog = wdComponentAPI.getWindowManager().createConfirmationWindow(errorMessage, windowHandler, "OK");
				  windowDialog.open();
				  windowDialog.setWindowPosition(300,250);
	  }
	}
	  else
	  {
		  String errorMessage = "Email id or phone no is not valid  !";
		  IWDEventHandlerInfo windowHandler = wdControllerAPI.getViewInfo().getViewController().findInEventHandlers("OK");
		  IWDConfirmationDialog windowDialog = wdComponentAPI.getWindowManager().createConfirmationWindow(errorMessage, windowHandler, "OK");
		  windowDialog.open();
		  windowDialog.setWindowPosition(300,250);
	  }
	}
	else
	{
		String errorMessage = "Date of joining should be Greater than the birth date and greater than date of conf !";
						  IWDEventHandlerInfo windowHandler = wdControllerAPI.getViewInfo().getViewController().findInEventHandlers("OK");
						  IWDConfirmationDialog windowDialog = wdComponentAPI.getWindowManager().createConfirmationWindow(errorMessage, windowHandler, "OK");
						  windowDialog.open();
						  windowDialog.setWindowPosition(300,250);
	}
		}
		else
		{
			String errorMessage = "Date of marriage should be greater than birth date !";
									  IWDEventHandlerInfo windowHandler = wdControllerAPI.getViewInfo().getViewController().findInEventHandlers("OK");
									  IWDConfirmationDialog windowDialog = wdComponentAPI.getWindowManager().createConfirmationWindow(errorMessage, windowHandler, "OK");
									  windowDialog.open();
									  windowDialog.setWindowPosition(300,250);
		}
	}
	else
	{
		if(((wdContext.currentEmpDetailElement().getZem_Doj()).getYear()-(wdContext.currentEmpDetailElement().getZem_Dob()).getYear()) >= 18 && (wdContext.currentEmpDetailElement().getZem_Doj()).compareTo(wdContext.currentEmpDetailElement().getZem_Doc()) >= 0 ){
			if(wdThis.emailTest(wdContext.currentEmpDetailElement().getZem_Mail())==true )
			{
			if(wdThis.validphoneno(wdContext.currentEmpDetailElement().getZem_Phone())==true)
			{
		  wdThis.Save();
			}
			  else
			  {
				String errorMessage = "phone no is not valid  !";
						  IWDEventHandlerInfo windowHandler = wdControllerAPI.getViewInfo().getViewController().findInEventHandlers("OK");
						  IWDConfirmationDialog windowDialog = wdComponentAPI.getWindowManager().createConfirmationWindow(errorMessage, windowHandler, "OK");
						  windowDialog.open();
						  windowDialog.setWindowPosition(300,250);
			  }
			}
			  else
			  {
				  String errorMessage = "Email id or phone no is not valid  !";
				  IWDEventHandlerInfo windowHandler = wdControllerAPI.getViewInfo().getViewController().findInEventHandlers("OK");
				  IWDConfirmationDialog windowDialog = wdComponentAPI.getWindowManager().createConfirmationWindow(errorMessage, windowHandler, "OK");
				  windowDialog.open();
				  windowDialog.setWindowPosition(300,250);
			  }
			}
			else
			{
				String errorMessage = "Date of joining should be Greater than the birth date and greater than date of conf !";
								  IWDEventHandlerInfo windowHandler = wdControllerAPI.getViewInfo().getViewController().findInEventHandlers("OK");
								  IWDConfirmationDialog windowDialog = wdComponentAPI.getWindowManager().createConfirmationWindow(errorMessage, windowHandler, "OK");
								  windowDialog.open();
								  windowDialog.setWindowPosition(300,250);
			}
	}
		
    }  
	catch(Exception e)
{
wdComponentAPI.getMessageManager().reportException("Error Message "+e.getMessage(),true);
wdComponentAPI.getMessageManager().reportException("Error Cause "+e.getCause(),true);
}
Former Member
0 Kudos

Hi,

I am not able to make out anything of the post.

Can you do one thing? Click on details when u get the error and in that you can find the line number.

One you get the line number plz post the code relevant to that line

Edited by: Santhosh Edla on Aug 28, 2009 3:16 PM

former_member40425
Contributor
0 Kudos

Hi,

I think exception is These two lines.

if ((wdContext.currentEmpDetailElement().getZem_Dom()).compareTo(dateb)> 0) 
{
if ((datej.getYear() - dateb.getYear()) >= 18&& datej.compareTo(datec) >= 0)

Because might be either dateb or datec or datej is blank and you can't compare any date with blank(null) date. And if datej or dateb is blank then you are trying to fetch year from blank date which is also not possible. In these both conditions null pointer exception will be thrown.

I hope it helps.

Regards,

Rohit

Edited by: Rohit Makkar on Aug 28, 2009 5:58 PM

Former Member
0 Kudos

That null pointer exception might be due to some other line of code. Check the line number in the details of the error.

Proabaly add try and catch statements for the lines of code where u get the error.

For an input feild of date type you will always get the error message " Enter the value in the format 25/11/1987"