Bom dia galera…
estou com um problema nullpointerexception…
abaixo vai o erro e meu programa.
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: java.lang.NullPointerException
Aula02.CadastrarFuncionarioServlet.doService(CadastrarFuncionarioServlet.java:65)
Aula02.CadastrarFuncionarioServlet.doPost(CadastrarFuncionarioServlet.java:43)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.NullPointerException
sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source)
java.lang.Double.parseDouble(Unknown Source)
Aula02.CadastrarFuncionarioServlet.doService(CadastrarFuncionarioServlet.java:58)
Aula02.CadastrarFuncionarioServlet.doPost(CadastrarFuncionarioServlet.java:43)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.19 logs.
Agora vai minhas linhas no Servlet
/**
-
Servlet implementation class CadastrarFuncionarioServlet
*/
@WebServlet("/CadastrarFuncionario")
public class CadastrarFuncionarioServlet extends HttpServlet {
private static final long serialVersionUID = 1L;/**
-
@see HttpServlet#HttpServlet()
*/
public CadastrarFuncionarioServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
-
@see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doService(request, response);
}
/**
- @return
-
@see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doService(request, response);
}
private void doService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String nome = request.getParameter(“nome”);
String sNascimento= request.getParameter(“nascimento”);
String sSalario = request.getParameter(“salario”);
String sSexo = request.getParameter(“sexo”);
String sTemporario = request.getParameter(“temporario”);Funcionario funcionario = null; DateFormat df = new SimpleDateFormat("dd/MM/yyyy"); try{ Date nascimento = df.parse(sNascimento); Double salario = Double.parseDouble(sSalario); Character sexo = sSexo.charAt(0); Boolean temporario = Boolean.parseBoolean(sTemporario); funcionario = new Funcionario(nome,nascimento, salario, sexo, temporario); } catch(Exception e) { throw new ServletException(e); } if (funcionario != null) { Dados.cadastrarFuncionario(funcionario); response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.write("<html><head><title>Funcionários Cadastrados</title></head></body>"); out.write("<hl>Funcionários Cadastrados</hl><ol>"); List<Funcionario> lista = Dados.listarFuncionarios(); for (Funcionario f: lista) out.write("<li><p>" + f.getNome()+ "</p></li>"); out.write("</ol>"); out.write("<p><hr /></p><p><a href='index.html'>Formulario de cadastro</a></p></body></html>"); out.close(); }
}
-
@see HttpServlet#HttpServlet()
}
Obs: quando coloco ou mouse sobre exception ele me indica as linhas do sNascimento e do sSalario
Agradeço a atenção
Abraço a tds!!!