Exception Stacktrace Extract:
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
[Request processing failed: java.lang.NullPointerException:
Cannot invoke "org.code2care.todolist.todolist.entities.ToDoRepository.findById(Object)"
because "this.toDoRepository" is null]
Reason:
The reason for this error is that you have defined a member variable of your Repository class in the Spring Controller class but have not @Autowired it. As it is not injected by the Spring IoC container, you get a NullPointerException when you try to do an operation over it
Solution:
Make sure you add @Autowired annotation above all your repositories in the Controller class,
Example:@Autowired
private ToDoListRepository toDoListRepository;
@Autowired
private ToDoRepository toDoRepository;

Provide Feedback For This Article
We take your feedback seriously and use it to improve our content. Thank you for helping us serve you better!
😊 Thanks for your time, your feedback has been registered!
Comments & Discussion
Facing issues? Have questions? Post them here! We're happy to help!