0

this is the error that i'm getting just when i'm taking input from a HTML FORM and hitting submit.

here's my controller file:

package com.employee.employeesystem.controller;

import org.springframework.stereotype.Controller;    
import org.springframework.web.bind.annotation.GetMapping;    
import org.springframework.web.bind.annotation.ModelAttribute;    
import org.springframework.web.bind.annotation.PostMapping;    
import org.springframework.web.bind.annotation.RestController;    
import com.employee.employeesystem.entity.Employee;    
import com.employee.employeesystem.service.cycleService;

@Controller
public class empController {
    
    private cycleService service;
    
    @GetMapping("/")
    public String home() {
        return "index";
    }
    
    @GetMapping("/addcycle")
    public String addCycleForm() {
        return "Add_cycle";
    }
    
    @PostMapping("/register")
    
    public String cycleRegister(@ModelAttribute Employee e) {
        System.out.println(e);
        service.addCycle(e);
        return "redirect:/";
    }
}
Stultuske
  • 9,296
  • 1
  • 25
  • 37
  • what exactly is your question? as to your situation: you don't provide a custom error handling, so the default is being used – Stultuske Aug 11 '22 at 05:50
  • as for your image: You don't instantiate your service, nor do you autowire it, yet you try to call the addCycle method on it. Does it really surprise you that it throws a NullPointerException? – Stultuske Aug 11 '22 at 05:51
  • There is no `@Autowire` on your service. Or even better make it `final` and create a constructor. – M. Deinum Aug 11 '22 at 06:13
  • @M.Deinum since the field isn't autowired, how is this a duplicate of "Why is my Spring Autowired field null? " ? – Stultuske Aug 11 '22 at 06:24

0 Answers0