Nullpointerexception in Java web

Asked

Viewed 95 times

0

I’m having a problem in a JSP that should insert a project to my work returning me as an error, this virtually identical an exercise I did earlier, so I don’t understand the reason for the error.

Error:

org.apache.jasper.JasperException: An exception occurred processing
[/jsp/projeto/validaInserirProjeto.jsp] at line [14]

11:     
12:     Funcionario funcionario = (Funcionario) session.getAttribute("UsuarioLogado");
13:     
14:     Projeto projeto = new Projeto(0, nome, descricao, dataObtido, dataEntregue, funcionario.getIdFuncionario());
15:     ProjetoController projCont = new ProjetoController();
16:     projeto = projCont.inserirProjeto(projeto);
17: 
java.lang.NullPointerException
    org.apache.jsp.jsp.projeto.validaInserirProjeto_jsp._jspService(validaInserirProjeto_jsp.java:128)
<%
    String nome = request.getParameter("NOME");
    String descricao = request.getParameter("DESCRICAO");
    String dataObtido = request.getParameter("DATAOBTENCAO");
    String dataEntregue = request.getParameter("DATAENTREGUE");

    Funcionario funcionario = (Funcionario) session.getAttribute("UsuarioLogado");

    Projeto projeto = new Projeto(0, nome, descricao, dataObtido, dataEntregue, funcionario.getIdFuncionario());
    ProjetoController projCont = new ProjetoController();
    projeto = projCont.inserirProjeto(projeto);
%>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Projeto cadastrado</title>
    </head>
    <body>
        <h1>Projeto cadastrado com sucesso em seu inventario, <%=funcionario.getNome()%></h1><br><br>
        <h1>Id Projeto           =  <%=projeto.getIdProjeto()%></h1>
        <h1>Nome                   =  <%=projeto.getNome()%></h1>
        <h1>Descrição              =  <%=projeto.getDescricao()%></h1>
        <h1>Data Obtenção          =  <%=projeto.getDataObtido()%></h1>
        <h1>Data Entregue         =  <%=projeto.getDataEntregue()%></h1>
    </body>
</html>
  • Put the whole mistake, so there’s no way to know where the mistake is.

  • org.apache.Jasper.Jasperexception: An Exception occurred Processing [/jsp/project/validationInserirProjeto.jsp] at line [14] 11: 12: Funcionaio funcionario = (Funcionario) Session.getattribute("Usuariodo"); 13: 14: Projeto = new Projeto(0, nome, descricao, dataObtido, dataEntregue, funcionario.getIdFuncionario());&#xA;15: ProjetoController projCont = new ProjetoController();&#xA;16: projeto = projCont.inserirProjeto(projeto);&#xA;17:

  • java.lang.Nullpointerexception org.apache.jsp.jsp.project.validatorProjeto_jsp. _jspService(validationInserirProjeto_jsp.java:128)

  • You can [Dit] the question and add the error information, so the information gets concentrated in one place

  • Yes, actually from the beginning I had put it complete, but they edited my doubt for some reason removing all the more important part that was the mistake itself. I updated again, thanks for the advice.

  • In valida insert project goes only up to line 36. I’m not getting what’s going wrong.

  • Can you put the most levels of stacktrace?

  • funcionario is void.

Show 3 more comments

1 answer

1

Funcionario funcionario = (Funcionario) session.getAttribute("UsuarioLogado");

In this case, there is no employee instance. When calling funcionario.getIdFuncionario() generates the error.

Nullpointerexception is an exception indicating that the application tried to use a reference to an object that was null

  • I’m sorry, but if it is NullPointerException (how the question title points) has nothing to do with the zero value

  • vi now, should have put null, but already corrected!

  • Passing null in the constructor does not cause NPE. What causes NPE is trying to access a method or attribute of a variable whose value is null. And it is often acceptable to pass null on the builder

Browser other questions tagged

You are not signed in. Login or sign up in order to post.