1. java
  2. android
  3. c#
  4. .net
  5. javascript
  6. php
  7. jquery
  8. html
  9. sql

NullPointerException

Sei que é um erro comum por aqui mas acredito que estou instanciando da forma correta. Segue os códigos: jsf

<h:form id="formNovo">
                    <p:growl id="growl" />
                    <p:dialog id="dialogNovo" header="Cadastro de Porta"
                        widgetVar="novo" resizable="false">
                        <h:panelGrid id="painelNovo" columns="2" cellpadding="2">
                            <h:outputText value="Porta"  />
                            <p:selectOneMenu value="#{PortaBean.porta.numeroPorta}" style="width:170px" required="true" requiredMessage="Selecione algum numero">
                             <f:selectItem itemLabel="Rele 1" itemValue="S1"/>
                             <f:selectItem itemLabel="Rele 2" itemValue="S2"/>
                             <f:selectItem itemLabel="Rele 3" itemValue="S3"/>
                             <f:selectItem itemLabel="Rele 4" itemValue="S4"/>
                             <f:selectItem itemLabel="Rele 5" itemValue="S5"/>
                             <f:selectItem itemLabel="Rele 6" itemValue="S6"/> 
                             <f:selectItem itemLabel="Analógico 1" itemValue="A1"/>
                             <f:selectItem itemLabel="Analógico 2" itemValue="A2"/>
                             <f:selectItem itemLabel="Digital 1" itemValue="D1"/>
                             <f:selectItem itemLabel="Digital 2" itemValue="D2"/>                             
                            </p:selectOneMenu>

                            <h:outputText value="Reservatorio" />
                            <p:selectOneMenu  value="#{PortaBean.reservatorio.idReservatorio}" filter="true" filterMatchMode="startsWith"  style="width:170px" required="true" requiredMessage="Selecione algum Reservatorio.">
                                <f:selectItem itemLabel="Selecione o Reservatorio" itemValue="0"/>
                                <f:selectItems value="#{PortaBean.listaReservatorio}"
                                    var="reservatorio" itemLabel="#{reservatorio.nomeReservatorio}"
                                    itemValue="#{reservatorio.idReservatorio}" />
                            </p:selectOneMenu>

                            <h:outputText value="Bomba" />
                            <p:selectOneMenu  value="#{PortaBean.bomba.idBomba}" filter="true" filterMatchMode="startsWith"  style="width:170px" required="true" requiredMessage="Selecione alguma bomba.">
                                <f:selectItem itemLabel="Selecione a Bomba" itemValue="0"/>
                                <f:selectItems value="#{PortaBean.listaBomba}"
                                    var="bomba" itemLabel="#{bomba.nomeBomba}"
                                    itemValue="#{bomba.idBomba}" />
                            </p:selectOneMenu>

                            <h:outputText value="Placa" />
                            <p:selectOneMenu value="#{PortaBean.placa.idPlaca}"  style="width:170px" required="true" requiredMessage="Selecione alguma placa.">
                                <f:selectItem itemLabel="Selecione a Placa" itemValue="0" />
                                <f:selectItems value="#{PortaBean.listaPlaca}" var="placa"
                                    itemLabel="#{placa.nomePlaca}" itemValue="#{placa.idPlaca}" />
                            </p:selectOneMenu>
                            <h:outputText value="Tipo de Porta" />
                            <p:selectOneMenu value="#{PortaBean.tipo.idTipoPorta}"  style="width:170px" required="true" requiredMessage="Selecione algum tipo de porta.">
                                <f:selectItem itemLabel="Selecione o tipo" itemValue="0" />
                                <f:selectItems value="#{TipoBean.listaTipo}" var="tipo"
                                    itemLabel="#{tipo.nomeTipoPorta}" itemValue="#{tipo.idTipoPorta}" />
                            </p:selectOneMenu>

                            <p:commandButton ajax="true" oncomplete="PF('novo').show();" id="limpar" value="Limpar" update="formNovo" actionListener="#{PortaBean.limpar}"/>
                            <p:commandButton id="cadastrar" ajax="false" value="Cadastrar"
                                actionListener="#{PortaBean.CadastrarPorta()}"
                                update=":formGrid growl" />
                        </h:panelGrid>
                    </p:dialog>
                </h:form>

método

public void CadastrarPorta(){
        System.out.println("Bomba: "+ porta.getBomba().getIdBomba());
        System.out.println("Reservatório: "+porta.getReservatorio().getIdReservatorio());
        System.out.println();
        System.out.println();
        portaDAO.salvar(porta);

    }

código do erro:

type Exception report

message

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:659)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
root cause

java.lang.NullPointerException
    br.com.auttec.monitora.bean.PortaBean.CadastrarPorta(PortaBean.java:34)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    java.lang.reflect.Method.invoke(Unknown Source)
    org.apache.el.parser.AstValue.invoke(AstValue.java:278)
    org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:274)
    com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    javax.faces.event.MethodExpressionActionListener.processAction(MethodExpressionActionListener.java:147)
    javax.faces.event.ActionEvent.processListener(ActionEvent.java:88)
    javax.faces.component.UIComponentBase.broadcast(UIComponentBase.java:813)
    javax.faces.component.UICommand.broadcast(UICommand.java:300)
    javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
    javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
    com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
    javax.faces.webapp.FacesServlet.service(FacesServlet.java:646)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:368)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
    org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:97)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:100)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:78)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:119)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:35)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:187)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:79)
    org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:380)
    org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:169)
    org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
    org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.47 logs.

Alguma sugestão?

  • Poste o código do erro. E o código do dao. Debugue para ver onde está dando o erro.

    Pablo Ferreira Rocha   06 de ago de 2015
  • Provavelmente algum Bean seu não está instanciado, coloca o código de erro ai.

    Paulo Carvalho   07 de ago de 2015
  1. Você vai ver essas setas em qualquer página de pergunta. Com elas, você pode dizer se uma pergunta ou uma resposta foram relevantes ou não.
  2. Edite sua pergunta ou resposta caso queira alterar ou adicionar detalhes.
  3. Caso haja alguma dúvida sobre a pergunta, adicione um comentário. O espaço de respostas deve ser utilizado apenas para responder a pergunta.
  4. Se o autor da pergunta marcar uma resposta como solucionada, esta marca aparecerá.
  5. Clique aqui para mais detalhes sobre o funcionamento do GUJ!

2 respostas

Não é a resposta que estava procurando? Procure outras perguntas com as tags jsf ou faça a sua própria pergunta.