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" >
Paste the stack of errors here. Help us help you.
– josivan
One of its variables is not being loaded. but only with that can not to know what is.
– Marco Souza
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)
– Renan Pompeu
Someone who can help me?
– Renan Pompeu
see if
dadospessoaisrepo
is being injected correctly.– josivan
public class Dadospessoalsrepo Implements Serializable { private Static final long serialVersionUID = 1L; @Inject Private entitymanager manager; public Datessoal save(Datessal dataPersonals) { Return manager.merge(dataPersonals); }
– Renan Pompeu
The instance of
dadospessoaisrepo
is being injected correctly in the classPesquisa
?– josivan
This doubt also could not solve about injection in the class Search ... put @Inject Private Datapersonal Information ;
– Renan Pompeu
@Renanpompeu, you need to make sure that class is being injected correctly. The absence of it (failure in the injection) would launch a
NullPointerException
.– josivan
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
– Renan Pompeu
I searched in several forums and found no answer that would solve my question
– Renan Pompeu