Ajuda com nullPoint

5 respostas
fred_cbranco

Fala galera estou com um problema ai com este erro do diabo hehehhhee
ao abrir uma pagina ele da este erro.
mais a pagina é simples nao tinha pq esta dando, segue ai o codigo para verem

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core">
    <ui:composition template="template.xhtml">
        <ui:define name="conteudo">
            <h:form styleClass="formulario">
                <ui:include src="cadastro-selecao.xhtml"/>
                <ui:include src="listagem-selecoes.xhtml"/>
            </h:form>
        </ui:define>
    </ui:composition>
</html>

tem o template tambem

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html">
    <h:head>
        <title>Copa do Mundo</title>
        <link rel="stylesheet" href="css/style.css" type="text/css"/>
    </h:head>
    <h:body>
        <div id="header">
            <img class="logo" src="k19-logo.png" />
            <h:outputLink styleClass="botao" value="selecoes.xhtml">Selecoes</h:outputLink>
            <h:outputLink styleClass="botao" value="jogadores.xhtml">Jogadores</h:outputLink>
                <hr/>
        </div>
        <ui:insert name="conteudo"> Espaço para o conteúdo da tela </ui:insert>
        <div id="footer" style="text-align: center">
            <hr />
            &copy; 2010 K19. Todos os direitos reservados.
        </div>
    </h:body>
</html>

alguem sabe pq deste erro:

11/01/2012 13:45:50 com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
GRAVE: Error Rendering View[/selecoes.xhtml]
javax.el.ELException: /listagem-selecoes.xhtml @16,29 value="#{selecaoBean.selecoes}": Error reading 'selecoes' on type beans.SelecaoBean
        at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:107)
        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)
        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)
        at javax.faces.component.UIData.getValue(UIData.java:554)
        at javax.faces.component.UIData.getDataModel(UIData.java:1248)
        at javax.faces.component.UIData.setRowIndex(UIData.java:447)
        at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:81)
        at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:823)
        at javax.faces.component.UIData.encodeBegin(UIData.java:937)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1611)
        at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
        at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
        at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
        at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
        at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
        at Repositorios.SelecaoRepository.getSelecoes(SelecaoRepository.java:31)
        at beans.SelecaoBean.getSelecoes(SelecaoBean.java:38)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
        at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
        at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
        at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
        at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
        at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102)
        ... 35 more
11/01/2012 13:48:51 com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
GRAVE: Error Rendering View[/selecoes.xhtml]
javax.el.ELException: /listagem-selecoes.xhtml @16,29 value="#{selecaoBean.selecoes}": Error reading 'selecoes' on type beans.SelecaoBean
        at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:107)
        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:190)
        at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:178)
        at javax.faces.component.UIData.getValue(UIData.java:554)
        at javax.faces.component.UIData.getDataModel(UIData.java:1248)
        at javax.faces.component.UIData.setRowIndex(UIData.java:447)
        at com.sun.faces.renderkit.html_basic.TableRenderer.encodeBegin(TableRenderer.java:81)
        at javax.faces.component.UIComponentBase.encodeBegin(UIComponentBase.java:823)
        at javax.faces.component.UIData.encodeBegin(UIData.java:937)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1611)
        at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
        at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:848)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1613)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
        at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1616)
        at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:380)
        at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:126)
        at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:127)
        at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
        at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
        at javax.faces.webapp.FacesServlet.service(FacesServlet.java:313)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
        at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:859)
        at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:579)
        at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1555)
        at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.NullPointerException
        at Repositorios.SelecaoRepository.getSelecoes(SelecaoRepository.java:31)
        at beans.SelecaoBean.getSelecoes(SelecaoBean.java:38)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at javax.el.BeanELResolver.getValue(BeanELResolver.java:62)
        at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
        at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
        at org.apache.el.parser.AstValue.getValue(AstValue.java:123)
        at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
        at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:102)
        ... 35 more

5 Respostas

fred_cbranco

vi que o erro esta em

GRAVE: Error Rendering View[/selecoes.xhtml]
javax.el.ELException: /listagem-selecoes.xhtml @16,29 value="#{selecaoBean.selecoes}": Error reading 'selecoes' on type beans.SelecaoBean

mas nao sei onde posso esta erradndo no bean, estou seguindo a apostila do k-19

segue o bean

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package beans;

import Repositorios.SelecaoRepository;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.persistence.EntityManager;
import modelo.Selecao;

/**
 *
 * @author Fred
 */
@ManagedBean
public class SelecaoBean {

    @ManagedProperty(value = "#{entityManager}")
    private EntityManager entityManager;
    private Selecao selecao = new Selecao();

    public void adiciona() {
        SelecaoRepository repository = new SelecaoRepository(this.getEntityManager());
        repository.adiciona(this.getSelecao());
        this.setSelecao(new Selecao());
    }
    public void remove(Selecao selecao) {
        SelecaoRepository repository = new SelecaoRepository(this.entityManager);
        repository.remove(selecao);
}

    public List<Selecao> getSelecoes() {
        SelecaoRepository repository = new SelecaoRepository(this.getEntityManager());
        return repository.getSelecoes();
    }


    /**
     * @return the entityManager
     */
    public EntityManager getEntityManager() {
        return entityManager;
    }

    /**
     * @param entityManager the entityManager to set
     */
    public void setEntityManager(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    /**
     * @return the selecao
     */
    public Selecao getSelecao() {
        return selecao;
    }

    /**
     * @param selecao the selecao to set
     */
    public void setSelecao(Selecao selecao) {
        this.selecao = selecao;
    }
// GETTERS AND SETTERS
}
renanreismartins

opa, é importante aprender oq é uma NullPointerException, qdo e pq ela acontece…

faça um debug no seu codigo veja se seu repository não está nulo na linha que a exceção é lançada, veja tb o método getSelecoes()

abrasssss

fred_cbranco

Ja dei uma olhada e nao sei como debugar com o netbeans
o repositary esta ai

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Repositorios;

import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.Query;
import modelo.Selecao;

/**
 *
 * @author Fred
 */
public class SelecaoRepository {

    private EntityManager entityManager;

    public SelecaoRepository(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    public void adiciona(Selecao selecao) {
        this.entityManager.persist(selecao);
        this.entityManager.flush();
    }

    public List<Selecao> getSelecoes() {
        Query query = this.entityManager.createQuery("select s from Selecao as s");
        return query.getResultList();
    }

    public void remove(Selecao selecao) {
        this.entityManager.remove(selecao);
        this.entityManager.flush();
    }
}
R

Você chegou a criar o método getSelecoes() em algum lugar?
pois pelo que eu vi nos seus getters e setters só tem o getSelecao() e o setSelecao()…

renanreismartins

seu entityManager está nulo no seu repositorio.

amigo, antes de continuar desenvolvendo é fundamental aprender debugar.

abrasssss

Criado 11 de janeiro de 2012
Ultima resposta 11 de jan. de 2012
Respostas 5
Participantes 3