GUJ Discussões   :   últimos tópicos   |   categorias   |   GUJ Respostas

Erro no controler de um projeto em JSF

java
jsf
Tags: #<Tag:0x00007fbf1d1fbb78> #<Tag:0x00007fbf1d1e3e88>

#1

Ao tentar mostrar resultados de uma tabela mapeada, ele mostra os erros abaixo.

Estou entendendo que o problema pode ser no persistir, isto é, não está persistindo os mapeamentos definidos.

Estou com este erro e não consigo resolver.

mar 20, 2017 11:24:54 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
GRAVE: Error Rendering View[/public/index.xhtml]
javax.el.ELException: /public/index.xhtml: Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler
at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:90)
at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
Caused by: com.sun.faces.mgbean.ManagedBeanCreationException: Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:227)
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:94)
at org.apache.el.parser.AstValue.getValue(AstValue.java:137)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
… 33 more
Caused by: com.sun.faces.spi.InjectionProviderException
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:115)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:95)
at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:221)
… 47 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:113)
… 49 more
Caused by: java.lang.ClassCastException: br.com.netsoft.desif.model.endereco.PaisEntity cannot be cast to java.util.List
at br.com.netsoft.desif.controler.endereco.PaisControler.init(PaisControler.java:32)
… 54 more

mar 20, 2017 11:24:54 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/desif] threw exception [Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler] with root cause
java.lang.ClassCastException: br.com.netsoft.desif.model.endereco.PaisEntity cannot be cast to java.util.List
	at br.com.netsoft.desif.controler.endereco.PaisControler.init(PaisControler.java:32)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:113)
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:95)
	at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:221)
	at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
	at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
	at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
	at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
	at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
	at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
	at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
	at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:94)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:137)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
	at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
	at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
	at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
	at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
	at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
	at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
	at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)

#2

Muitas vezes, a stack do erro nos diz o que acontece
Caused by: java.lang.ClassCastException: br.com.netsoft.desif.model.endereco.PaisEntity cannot be cast to java.util.List te diz algo? Em PaisController…


#3

Está dizendo que não pode ser uma lista.

Foi corrigido.

Mas deu outro erro:

A linha 40 está assim:

ArrayList paises = (ArrayList) paisDao.listarPaises();

Causa: GRAVE:
Servlet.service() for servlet [Faces Servlet] in context with path [/desif] threw exception [Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler] with root cause
java.lang.NullPointerException
at br.com.netsoft.desif.controler.endereco.PaisControler.init(PaisControler.java:40)

mar 21, 2017 12:19:04 AM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
GRAVE: Error Rendering View[/public/index.xhtml]
javax.el.ELException: /public/index.xhtml: Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler
	at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:90)
	at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
	at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
	at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
Caused by: com.sun.faces.mgbean.ManagedBeanCreationException: Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler
	at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:227)
	at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
	at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
	at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
	at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
	at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
	at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
	at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
	at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:94)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:137)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
	at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
	at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
	at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
	at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
	... 33 more
Caused by: com.sun.faces.spi.InjectionProviderException
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:115)
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:95)
	at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:221)
	... 47 more
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:113)
	... 49 more
Caused by: java.lang.NullPointerException
	at br.com.netsoft.desif.controler.endereco.PaisControler.init(PaisControler.java:40)
	... 54 more

mar 21, 2017 12:19:04 AM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/desif] threw exception [Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler] with root cause
java.lang.NullPointerException
	at br.com.netsoft.desif.controler.endereco.PaisControler.init(PaisControler.java:40)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:113)
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:95)
	at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:221)
	at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
	at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
	at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
	at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
	at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
	at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
	at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
	at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:94)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:137)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
	at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
	at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
	at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
	at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
	at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
	at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
	at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)

#4

Significa que você está tentando realizar o cast em um objeto que está nulo.
Para que você use a linha 40 como está, precisa certificar-se de que o método listarPaises da classe PaisDao está, realmente, devolvendo algo diferente de nulo.


#5

Se possível, pode me dar um Help.

Meu controller
package br.com.netsoft.desif.controler.endereco;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import javax.faces.bean.ManagedBean;

import br.com.netsoft.desif.dao.endereco.PaisDao;
import br.com.netsoft.desif.model.endereco.PaisEntity;

@ManagedBean(name = "paisControler")
@RequestScoped
public class PaisControler extends PaisEntity {

	private static final long serialVersionUID = -8396738159447021720L;

	private List<PaisEntity> paises;

	private PaisDao paisDao;

	public List<PaisEntity> getPaises() {
		if (paises == null) {
			return new ArrayList<PaisEntity>();
		}
		return paises;
	}

	public void setPaises(List<PaisEntity> paises) {
		this.paises = paises;
	}

	@PostConstruct
	public void init() {
		System.out.println("Página inicial de países.");
		@SuppressWarnings("unused")
		List<PaisEntity> paisesBusca = paisDao.listarPaises();
		
		ArrayList<PaisEntity> paises = (ArrayList<PaisEntity>) paisDao.listarPaises();

		for (Iterator<?> iterator = paises.iterator(); iterator.hasNext();) {
			PaisEntity pais = (PaisEntity) iterator.next();
			pais.setId(pais.getId());
			pais.setDescricao(pais.getDescricao());
			paises.add(pais);
		}

		this.setPaises(paises);
	}

	public String getMensagem() {
		return "Teste";
	}

}

Meu DAO

package br.com.netsoft.desif.dao.endereco;

import java.io.Serializable;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import br.com.netsoft.desif.model.endereco.PaisEntity;

public class PaisDao implements Serializable {

	private static final long serialVersionUID = 1402488530698938353L;

	final private String hql = " p FROM PaisEntity p ";

	EntityManager em;

	public List<PaisEntity> listarPaises() {

		StringBuilder hqlSelect = new StringBuilder(hql);

		final String query = "SELECT " + hqlSelect;

		Query querySelect = em.createQuery(query);

		@SuppressWarnings("unchecked")
		List<PaisEntity> resultList = querySelect.getResultList();

		return resultList;

	}

}

Meu view

<h:head>
	<title>Hello JSF!</title>
</h:head>
<h:body>
      #{paisControler.mensagem}
      
	<h:dataTable var="pais" value="#{paisControler.paises}">

		<h:column headerText="Id">
			<h:outputText value="#{pais.id}" />
		</h:column>

		<h:column headerText="Year">
			<h:outputText value="#{pais.descricao}" />
		</h:column>

	</h:dataTable>

</h:body>

</html>

#6

Entidade

package br.com.netsoft.desif.model.endereco;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;

public class PaisEntity implements Serializable {

	private static final long serialVersionUID = 7784827196506672790L;
	private Long id;
	private String descricao;

	@Id
	@Column(name = "pai_id")
	@SequenceGenerator(name = "enderecos.end_pais_pai_id_seq", sequenceName = "enderecos.end_pais_pai_id_seq", allocationSize = 1)
	@GeneratedValue(generator = "enderecos.end_pais_pai_id_seq", strategy = GenerationType.SEQUENCE)
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Column(name = "pai_descricao")
	public String getDescricao() {
		return descricao;
	}

	public void setDescricao(String descricao) {
		this.descricao = descricao;
	}

}

#7

Desculpe, agora que postou o código inteiro é que vi.
Onde você instancia o objeto paisDao?
Só vi a declaração aqui private PaisDao paisDao; e a chamada a um método dele aqui List<PaisEntity> paisesBusca = paisDao.listarPaises();


#8

Nesta parte do código que você citou.


#9

Quando mudou?
Ou você usa um new para criar um novo objeto ou você usa anotação de injeção ou você mapeia isso num xml para injeção também.
Pois apenas isso private PaisDao paisDao;, para mim (e para o compilador e para a JVM) é só a declaração.


#10

Entendo, posso estar errado, mas o retorno desta função é uma lista de PaisEntity, por isto disse.

Mas pode me dar um exemplo de como ajustar ?


#11

Não estou mais me referindo ao retorno do método listarPaises. Eu me refiro ao fato de você só ter declarado o PaisDao e não tê-lo instanciado.
Se você fizer isso:
private String nome; public void teste() { System.out.println(nome.toUpperCase()); }
Receberá como retorno da execução do método um NullPointerException, pois não instanciou a variável “nome”.
É o mesmo que acontece com a chamada ao método listarPaises, você tem uma instância nula de paisDao e como eu disse antes, você precisa fazer isso paisDao = new PaisDao(); em algum lugar do teu código, antes de invocar isso @SuppressWarnings("unused") List<PaisEntity> paisesBusca = paisDao.listarPaises();


#12

Assim ?

@PostConstruct
	public void init() {
		System.out.println("Página inicial de países.");

	paisDao = new PaisDao();

		@SuppressWarnings("unused")
		List<PaisEntity> paisesBusca = paisDao.listarPaises();

#13

Exato. Isso deve resolver o NullPointerException


#14

Agora deu erro no hql, nesta linha:

Query querySelect = em.createQuery(query);

Acho eu que é a mesma coisa.

package br.com.netsoft.desif.dao.endereco;

import java.io.Serializable;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import br.com.netsoft.desif.model.endereco.PaisEntity;

public class PaisDao implements Serializable {

	private static final long serialVersionUID = 1402488530698938353L;

	final private String hql = " p FROM PaisEntity p ";

	EntityManager em;

	public List<PaisEntity> listarPaises() {

		StringBuilder hqlSelect = new StringBuilder(hql);

		final String query = "SELECT " + hqlSelect;

		Query querySelect = em.createQuery(query);

		@SuppressWarnings("unchecked")
		List<PaisEntity> resultList = querySelect.getResultList();

		return resultList;

	}

}

#15

Mesma situação da anterior. Onde você instancia o EntityManager?
Está utilizando JPA?
Se sim, está faltando colocar a anotação referente ao persistence unity.
Dá uma olhada nisso.


#16

Pesquisei, fiz alguns testes mas o erro continua.

Meu persistes esta correto ?

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
	version="1.0">

	<persistence-unit name="desif" transaction-type="RESOURCE_LOCAL">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<non-jta-data-source>java:/desifutf8</non-jta-data-source>
		<!-- Enderecos -->
		<class>br.com.netsoft.desif.model.endereco.PaisEntity</class>

		<properties>
			<property name="hibernate.hbm2ddl.auto" value="none" />
			<property name="hibernate.show_sql" value="update" />
			<property name="show_sql" value="true" />
			<property name="hibernate.format_sql" value="true" />
			<property name="hibernate.connection.autocommit" value="false" />
			<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
		</properties>
	</persistence-unit>
</persistence>

#17

Se o persistence.xml está ok, não sei e nem vou verificar.
A tua dificuldade está em quando injetar um objeto.
Neste caso, você deve anotar o teu EntityManager com a anotação @PersistenceContext


#18

Isto eu já tinha feito @Luiz_Augusto_Prado

@PersistenceContext
EntityManager em;

Coloquei o arquivo persistence.xml, pois achei que o erro poderia estar lá


#19

O erro persiste? Qual a mensagem? Pode ser mais claro quando colocar alguma informação?


#20

@Luis_Augusto_Santos, fazendo o debug, o sistema vai até a linha, Query querySelect = em.createQuery(query);

Com a anotação ou não entendo que o erro é o mesmo.

mar 21, 2017 3:35:03 PM com.sun.faces.application.view.FaceletViewHandlingStrategy handleRenderException
GRAVE: Error Rendering View[/index.xhtml]
javax.el.ELException: /index.xhtml: Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler
	at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:90)
	at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
	at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
	at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)
Caused by: com.sun.faces.mgbean.ManagedBeanCreationException: Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler
	at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:227)
	at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
	at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
	at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
	at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
	at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
	at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
	at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
	at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:94)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:137)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
	at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
	at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
	at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
	at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
	... 33 more
Caused by: com.sun.faces.spi.InjectionProviderException
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:115)
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:95)
	at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:221)
	... 47 more
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:113)
	... 49 more
Caused by: java.lang.NullPointerException
	at br.com.netsoft.desif.dao.endereco.PaisDao.listarPaises(PaisDao.java:27)
	at br.com.netsoft.desif.controler.endereco.PaisControler.init(PaisControler.java:43)
	... 54 more

mar 21, 2017 3:35:03 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet [Faces Servlet] in context with path [/desif] threw exception [Um erro ocorreu ao realizar a injeção de recurso no bean gerenciado paisControler] with root cause
java.lang.NullPointerException
	at br.com.netsoft.desif.dao.endereco.PaisDao.listarPaises(PaisDao.java:27)
	at br.com.netsoft.desif.controler.endereco.PaisControler.init(PaisControler.java:43)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokeAnnotatedMethod(WebContainerInjectionProvider.java:113)
	at com.sun.faces.vendor.WebContainerInjectionProvider.invokePostConstruct(WebContainerInjectionProvider.java:95)
	at com.sun.faces.mgbean.BeanBuilder.invokePostConstruct(BeanBuilder.java:221)
	at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:103)
	at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409)
	at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269)
	at com.sun.faces.el.ManagedBeanELResolver.resolveBean(ManagedBeanELResolver.java:244)
	at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:116)
	at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
	at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
	at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:94)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:137)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:184)
	at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
	at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
	at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
	at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
	at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
	at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
	at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1859)
	at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:443)
	at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
	at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337)
	at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:783)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:798)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1441)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Unknown Source)