Fórum Problema na execução #406050
04/08/2011
0
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:62) Aula02.CadastrarFuncionarioServlet.doPost(CadastrarFuncionarioServlet.java:42) 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:56) Aula02.CadastrarFuncionarioServlet.doPost(CadastrarFuncionarioServlet.java:42) 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.
E está abaixo o meu programa
package Aula02;
import java.io.IOException;import java.io.PrintWriter;import java.text.DateFormat;import java.text.SimpleDateFormat;import java.util.Date;import java.util.List;
import javax.servlet.ServletException;import javax.servlet.annotation.WebServlet;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;
/** * 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(); } }
}
Aguardo uma resposta e agradeço a atenção...Abraço a tds!!!
Rodolpho Brasil
Curtir tópico
+ 0Posts
05/08/2011
Davi Costa
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");
adiciona:
System.out.println(nome);
System.out.println(sNascimento);
System.out.println(sSalario);
System.out.println(sSexo);
System.out.println(sTemporario);
E ver que não está vindo legal.
att Davi
Gostei + 0
05/08/2011
Dyego Carmo
Resolvido ?
Se sim, por favor feche o chamado :)
Valeu !
Gostei + 0
08/08/2011
Rodolpho Brasil
Gostei + 0
09/08/2011
Davi Costa
éo mesmo?
cola o stacktrace aqui se for outro.
...
@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");
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"); // vc olha no console quem vem nulo 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 rel='nofollow' href='index.html'>Formulario de cadastro</a></p></body></html>"); out.close(); } }
}
att Davi
Gostei + 0
11/08/2011
Rodolpho Brasil
Gostei + 0
12/08/2011
Rodolpho Brasil
Abraço a tdas!!!
Gostei + 0
12/08/2011
Rodolpho Brasil
Date nascimento = df.parse(sNascimento); Double salario = Double.parseDouble(sSalario);
Gostaria de saber como faço para solucionar esse problema...Pois estou achando que o erro são essas duas exceções....Agradeço a atenção...
Abraço a tds
Gostei + 0
12/08/2011
Rodolpho Brasil
Abraço a tdas!!!
Gostei + 0
12/08/2011
Rodolpho Brasil
Gostei + 0
12/08/2011
Davi Costa
Date nascimento = df.parse(sNascimento); Double salario = Double.parseDouble(sSalario);
Mais ou menos assim:
Date nascimento = null; Double salario = null;
if(.. verifica s estão vaziosou nao){
nascimento = df.parse(sNascimento);
salario = Double.parseDouble(sSalario);
}
att Davi
Gostei + 0
17/08/2011
Rodolpho Brasil
Gostei + 0
28/07/2013
Cristian Pimentel
abraços
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)