Reputation: 49
I get an error when I call a function in java.
The return type is void, and I just call it and display a string inside.
Here is the call of the bugging function :
@RequestMapping(method = RequestMethod.POST)
public String findDevicesByCriteria(@Valid @ModelAttribute Device device, BindingResult bindingResult, Model uiModel) {
if (isCriteriaEmpty(device)) {
uiModel.addAttribute("criteriaEmptyWarning", "error_search_criteria_empty");
return ViewConstants.DEVICE_SEARCH_VIEW;
}
identityService.searchDevices(device.getSerialNumber(), device.getOwner().getSiteName(), device.getIpAdress(), device.getInstallDate(), device.getEndDate()); // the error come from here
return ViewConstants.DEVICE_SEARCH_VIEW;
}
The prototype in the interface of the bugging function :
/**
* Search devices.
*
* @param sn the serial number of the device
* @param site the site of it
* @param ipAdress the ip adress of it
* @param installDt the install date of it
* @param endDt the end date of it
* @return the list of device
*/
void searchDevices(String sn, String site, String ipAdress, Date installDt, Date EndDt);
And finally the function that cause problem :
public void searchDevices(String sn, String site, String ipAdress, Date installDt, Date EndDt) {
System.out.println("toto");
}
Please advice
Regards
Upvotes: 0
Views: 84
Reputation: 3306
Check that none of the following objects is null.
identityService
device
device.getOwner()
Upvotes: 1
Reputation: 1
1.Plz. Confirm whether you have declared and defined the bean for identity service. (Most probably it would be @Autowired in your controller and defined as bean in your SpringBean context file) and correct the discrepancies found if any.
It would be far more easy to pin point the issue if you could share whole your controller file(from where the function is called and debug point on line from where null pointer is thrown).
Upvotes: 0
Reputation: 4065
Either of identityService
or service
has not been initialized and therefore is null. Then you get a NullPointerException
when you try to use it.
Upvotes: 0
Reputation: 8466
Check whether the device is null or not before accessing the values
if(device != null)
{
identityService.searchDevices(device.getSerialNumber(), device.getOwner().getSiteName(), device.getIpAdress(), device.getInstallDate(), device.getEndDate());
}
Upvotes: 1