Updated 2022-05-22 0
Viewed 17 times
0

I'm receiving a NullPointerExeception stating: Cannot invoke "com.capstone.happening_happy_hours.models.User.setPassword(String)" because "userTest" is null

@GetMapping("/changePassword") public String showForm(Model model, User user, @RequestParam(name = "from") String from) { User user1 = userDao.findUserByEmail(from); model.addAttribute("user", user1); return "/changePassword"; }

@PostMapping("/changePassword")
public String changePassword(@ModelAttribute User user, @RequestParam(name = "password") String password, @RequestParam(name = "passwordConfirm") String passwordConfirm) {
    User userTest = userDao.findByEmail(user.getEmail());
    if (password.equals(passwordConfirm)) {
        userTest.setPassword(passwordEncoder.encode(password));
        userDao.save(userTest);
    }
    return "redirect:/login";
}
🔴 No definitive solution yet