"java.lang.Nullpointerexception" in JSF Hibernate application

Asked

Viewed 59 times

0

My web application uses JSF/Hibernate , but when I run a search method in the BD it returns "java.lang.Nullpointerexception " . What will be the cause of the error ?

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.bean;


import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ViewScoped;
import javax.inject.Inject;
import com.entity.DadosPessoais;
import com.filter.DadosPessoaisFilter;
import com.repository.DadosPessoaisRepo;
import javax.faces.bean.ManagedBean;
import javax.inject.Named;


@ViewScoped
@Named
@ManagedBean(name="pesquisa")
public class Pesquisa implements Serializable {

    private static final long serialVersionUID = 1L;

    @Inject
    private DadosPessoaisRepo dadospessoaisrepo ;

    private DadosPessoaisFilter filtro;        
    private List<DadosPessoais> militarFiltrado;

    public Pesquisa() {
        filtro = new DadosPessoaisFilter();
    }

    public void pesquisar() {
        militarFiltrado = dadospessoaisrepo.filtrados(filtro);
    }

    public DadosPessoaisFilter getFiltro() {
        return filtro;
    }

    public List<DadosPessoais> getMilitarFiltrado() {
        return militarFiltrado;
    }

}

My view :

<h:form id="cadastro">
                    <p:fieldset style="background: #CDCDB4">
            <center><h2 style="font-family:Trebuchet MS,Arial, Helvetica; font-size:30px; color:#009999;">Pesquisa de Militares</h2></center>
                    </p:fieldset><br/>                 

                    <center><p:panelGrid columns="3" id="painel" style="margin-top: 20px" columnClasses="nome">
                            <p:outputLabel value="Nome" for="nome"/>
                            <p:inputText id="nome" size="60" value="#{DadosPessoaisBean.dadospessoais.nome}"/>          
                            <p:commandButton value="Pesquisar" action="#{pesquisa.pesquisar}" update="@form"/>
                        </p:panelGrid></center><br/><br/>

                    <center><p:dataTable value="#{pesquisa.militarFiltrado}" var="tbdados"  id="tabela" style="width:80%;" 
                               emptyMessage="Nenhum produto encontrado." paginatorAlwaysVisible="false" paginatorPosition="bottom"
                               rows="10" paginator="true" >    
  • 2

    Paste the stack of errors here. Help us help you.

  • One of its variables is not being loaded. but only with that can not to know what is.

  • Caused by: java.lang.Nullpointerexception at com.bean.Search.search(Search.java:38) at sun.reflect.Nativemethodaccessorimpl.invoke0(Native Method) at sun.reflect.Nativemethodaccessorimpl.invoke(Nativemethodaccessorimpl.java:62)

  • Someone who can help me?

  • see if dadospessoaisrepo is being injected correctly.

  • public class Dadospessoalsrepo Implements Serializable { private Static final long serialVersionUID = 1L; @Inject Private entitymanager manager; public Datessoal save(Datessal dataPersonals) { Return manager.merge(dataPersonals); }

  • The instance of dadospessoaisrepo is being injected correctly in the class Pesquisa?

  • This doubt also could not solve about injection in the class Search ... put @Inject Private Datapersonal Information ;

  • @Renanpompeu, you need to make sure that class is being injected correctly. The absence of it (failure in the injection) would launch a NullPointerException.

  • I believe so, but I reviewed the code and now it’s giving Grave error: javax.el.Propertynotfoundexception: /search.xhtml @29.95 value="#{search.filtro.name}": Target Unreachable, Identifier 'search' resolved to null

  • I searched in several forums and found no answer that would solve my question

Show 6 more comments
No answers

Browser other questions tagged

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