NullPointerException on method (NativeMethodAccessorImpl.invoke0(Native Method) [duplicate]

I’m creating a scheduled method to create last month invoices (currently set to every 5 seconds for testing purposes). I’m getting a NullPointerException on the line where I’m trying to get shiftServices from my shiftServiceService.

@Scheduled(cron = "*/5 * * * * *")
    public void createLastMonthInvoices() {
        List<Client> clients = clientService.getClientList();
        System.out.println("Clients size: " + clients.size());
        for (Client client : clients) {
            System.out.println("Client ID: " + client.getId());
            List<ShiftService> shiftServices = shiftServiceService.getLastMonthShiftServicesByClient(client.getId());
            if (!ObjectUtils.isEmpty(shiftServices)) {
                System.out.println("Services size: " + shiftServices.size());

Here is the shiftServiceService method itself.

public List<ShiftService> getLastMonthShiftServicesByClient(Long clientId) {
        Specification<ShiftService> spec = where(null);
        spec = spec.and(client(clientId));
        spec = spec.and(lastMonthServices());
        spec = spec.and(scheduledServices());

        return shiftServiceRepository.findAll(spec);

clientId is not null and outputs correctly, but the function itself is giving me an error like this:

java.lang.NullPointerException: null
    at com.bitweb.syda.service.invoice.InvoiceService.createLastMonthInvoices(
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(
    at java.base/java.lang.reflect.Method.invoke(
    at java.base/java.util.concurrent.Executors$
    at java.base/
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(
    at java.base/java.util.concurrent.ThreadPoolExecutor$
    at java.base/

2 Answers

there can be one things you can check. One is shiftServiceService object is initialized or not.

You are printing a null variable

System.out.println("Client ID: " + client.getId());

Archive from:

Leave a Reply

Your email address will not be published. Required fields are marked *