Type Exception Report
Message Cannot invoke "String.length()" because "text" is null
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
java.lang.NullPointerException: Cannot invoke "String.length()" because "text" is null java.base/java.text.SimpleDateFormat.parse(SimpleDateFormat.java:1474) java.base/java.text.DateFormat.parse(DateFormat.java:397) br.com.alura.gerenciador.servlet.AlteraEmpresaServlet.doPost(AlteraEmpresaServlet.java:30) javax.servlet.http.HttpServlet.service(HttpServlet.java:681) javax.servlet.http.HttpServlet.service(HttpServlet.java:764) org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
@WebServlet("/alteraEmpresa") public class AlteraEmpresaServlet extends HttpServlet { private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
System.out.println("Alterando empresa"); String nomeEmpresa = request.getParameter("nome"); String paramDataEmpresa = request.getParameter("data"); String paramId = request.getParameter("id"); Integer id = Integer.valueOf(paramId); Date dataAbertura = null; try { SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); dataAbertura = sdf.parse(paramDataEmpresa); } catch (ParseException e) { throw new ServletException(e); } System.out.println(id); Banco banco = new Banco(); Empresa empresa = banco.buscaEmpresaPelaId(id); empresa.setNome(nomeEmpresa); empresa.setDataAbertura(dataAbertura); response.sendRedirect("listaEmpresas");
}
}