简体   繁体   中英

Request processing failed; nested exception is java.lang.NumberFormatException: null

I'm getting error as Request processing failed; nested exception is java.lang.NumberFormatException: null Request processing failed; nested exception is java.lang.NumberFormatException: null .

Here is my code:

 @Controller
 @RequestMapping("/customerAdmin")
 public class CustomerAdmincontroller {
        @InitBinder
        public void initBinder(WebDataBinder binder) {
            binder.registerCustomEditor(Customer.class, "customer", new PropertyEditorSupport() {@
                Override
                public void setAsText(String customer) {
      setValue(new Customer(Integer.parseInt(customer)));
                }
            });
        }

        @RequestMapping(value = "/addProfile.htm", method = RequestMethod.GET)
        public ModelAndView addProfileForm(ModelMap model, HttpServletRequest request) {
            int id = Integer.parseInt(request.getParameter("id"));
            System.out.println(id);
            Profile profile = new Profile();
            Customer customer = new Customer(id);
            profile.setCustomer(customer);
            model.addAttribute("profile", profile);
            ModelAndView mav = new ModelAndView("addProfile");
            return mav;
        }
}

Am getting error as

Oct 16, 2014 4:31:47 PM invoke

SEVERE: Servlet.service() for servlet [dispatcherServlet] in context with path [/CustomerPortal] threw exception [Request processing failed; nested exception is java.lang.NumberFormatException: null] with root cause

when i run the project this error already show and i see this error in this Here but still it's error for me. any one can help me ? My controler :

@Autowired
    addozv stdDAO;

    private ServletRequest request;
    @SuppressWarnings({ "null"})  
          @RequestMapping(value="/addadmins" , method = RequestMethod.POST)
           public void addadmins(ModelMap model, HttpServletRequest requ) {
               String username = requ.getParameter("username");
               String password = requ.getParameter("password");
               String nozv = requ.getParameter("nozv");
               String namefamily = requ.getParameter("namefamily");
               String codemely = requ.getParameter("codemely");
               String father = requ.getParameter("father");
               String adress = requ.getParameter("adress");
               String telephone = requ.getParameter("telephone");
               admins adm=new admins();
               adm.setUsername(username);
               adm.setPassword(password);
               adm.setNozv(Integer.parseInt(nozv));
               adm.setNamefamily(namefamily);
               adm.setCodemely(Integer.parseInt(codemely));
               adm.setFather(father);
               adm.setAdress(adress);
               adm.setTelephone(Integer.parseInt(telephone));  
               stdDAO.add(adm);

Jdbc :

@Override
    public void add(admins adm) {
        String sql = "INSERT INTO admins " +
                "username, password, nozv, namefamily, codemely, father, adress, telephone) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
        Connection conn = null;
        try{
            conn = dataSource.getConnection();
            PreparedStatement ps=conn.prepareStatement(sql);
            ps.setString(1, adm.getUsername());
            ps.setString(2, adm.getPassword());
            ps.setInt(3, adm.getNozv());
            ps.setString(4, adm.getNamefamily());
            ps.setInt(5, adm.getCodemely());
            ps.setString(6, adm.getFather());
            ps.setString(7, adm.getAdress());
            ps.setInt(8, adm.getTelephone());
            ps.executeUpdate();
            ps.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);

            } finally {
                if (conn != null) {
                    try {
                conn.close();
            } catch (SQLException e) {}
        }       
}

and in jsp page it's true i don't know why already it's Error in this page. before this code i'm writing this code:

@SuppressWarnings("null")
   @RequestMapping(value="/addozvv" , method = RequestMethod.GET)
   public String addozv(ModelMap model) {
      model.addAttribute("title", "ozv");


      return "addozvv";
   }

   @SuppressWarnings("null")
   @RequestMapping(value="/addozvv" , method = RequestMethod.POST)
   public void showPageSaveozv(ModelMap model, HttpServletRequest req) {
       String Id = req.getParameter("nozviat");
       String namefamily = req.getParameter("namefamily");
       String codemely = req.getParameter("codemely");
       String father = req.getParameter("father");
       String adress = req.getParameter("adress");
       String otelephone = req.getParameter("otelephone");
       String znamefamily = req.getParameter("znamefamily");
       String zcodemely = req.getParameter("zcodemely");
       String office = req.getParameter("office");
       String ztelephone = req.getParameter("ztelephone");

      /////////////
      ozviat ozv = new ozviat();

      ozv.setId(Integer.parseInt(Id));   
      ozv.setNamefamily(namefamily); 

    ozv.setCodemely(Integer.parseInt(codemely));  
      ozv.setFather(father);   
      ozv.setAdress(adress);  
      ozv.setOtelephone(Integer.parseInt(otelephone));   
      ozv.setZnamefamily(znamefamily);   
      ozv.setZcodemely(Integer.parseInt(zcodemely));   
      ozv.setOffice(office); 
      ozv.setZtelephone(Integer.parseInt(ztelephone)); 
      stdDAO.insert(ozv);


   }

but when i Run the project it's ture but other one it's a error

如我所见,您可能在没有 id 参数的情况下调用 /addProfile.htm 并且 parseInt 在这一行中抛出 NPE:

int id = Integer.parseInt(request.getParameter("id"));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM