title: java.lang.NullPointerException while calling from controller
body: <p>My Spring Boot program is compiling without any issues, but whenever I click the registration link it throws NullPointerException error. I am really at a loss as to what may be causing this. Given below is the error:-</p>
  
  <pre><code>java.lang.NullPointerException: null
      at com.concretepage.controller.UserInfoController.registration(UserInfoController.java:32) ~[classes/:na]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_171]
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.8.0_171]
      at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.8.0_171]
  </code></pre>
  
  <p>The UserinfoController class is given below:-</p>
  
  <pre><code>import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.servlet.ModelAndView;
  
  import com.concretepage.entity.ProjectLevel;
  import com.concretepage.service.LevelService;
  import com.concretepage.service.UserInfoService;
  
  @Controller
  @RequestMapping("app")
  public class UserInfoController {
      @Autowired
      private UserInfoService userInfoService;
      private LevelService levelService;
  
      @GetMapping("login")
      public ModelAndView login() {
          ModelAndView mav = new ModelAndView();
          mav.setViewName("custom-login");
          return mav;
      }
  
      @GetMapping("registration")
      public ModelAndView registration() {
          ModelAndView mav = new ModelAndView();
          List&lt;ProjectLevel&gt; levels = levelService.getAllLevels();
          mav.addObject("Levels", levels);
          mav.setViewName("registration");
          return mav;
      }
  
      @GetMapping("secure/project-details")
      public ModelAndView getAllUserProjects() {
          ModelAndView mav = new ModelAndView();
          mav.addObject("userProjects", userInfoService.getAllUserProjects());
          mav.setViewName("projects");
          return mav;
      }
  </code></pre>
  
  <p>Error is at the line - </p>
  
  <pre><code>List&lt;ProjectLevel&gt; levels = levelService.getAllLevels();
  </code></pre>
  
  <p>The LevelServiceImpl class is as below:-</p>
  
  <pre><code>package com.concretepage.service;
  
  import java.util.List;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  
  import com.concretepage.entity.ProjectLevel;
  import com.concretepage.repositories.LevelRepository;
  
  @Service
  public class LevelServiceImpl implements LevelService {
      @Autowired
      private LevelRepository levelRepository;
  
      @Override
      public List&lt;ProjectLevel&gt; getAllLevels() {
          List&lt;ProjectLevel&gt; levelList = levelRepository.findAll();
          return levelList;
      }
  }
  </code></pre>