Erro ao tentar instanciar objeto Java no Flex

Boa noite meus amigos,

Estou estudando flex e me deparei com um erro do qual não consigo me livrar.

Me é exibido a seguinte mensagem:

Ao meu ver está tudo correto

Vejam o código do ContatoDAO

public class ContatoDAO extends AbstractDAO<Contato> {

	public ContatoDAO() {
		super("Contato");
	}

}[/code]

Agora do AbstractDAO

[code]package br.com.treinamento.modelo.dao;

import java.lang.reflect.Field;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import br.com.treinamento.database.ConnectionFactory;

public abstract class AbstractDAO<T> {

	private String tableName;
	private Connection con;
	private Class<T> clazz;
	private Field[] fields;

	@SuppressWarnings("unchecked")
	public AbstractDAO(String tableName) {
		this.tableName = tableName;
		con = ConnectionFactory.getConnection();

		try {
			clazz = (Class<T>) Class.forName("br.com.treinamento.modelo.beans."
					+ tableName);
			fields = clazz.getDeclaredFields();

		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}

	}

	@SuppressWarnings({ "finally" })
	public ArrayList<T> getLista() {
		ArrayList<T> lista = new ArrayList<T>();

		String sql = String.format("SELECT * FROM %s ORDER BY id", tableName);

		try {
			PreparedStatement pstm = con.prepareStatement(sql);
			ResultSet rs = pstm.executeQuery();

			while (rs.next()) {

				lista.add(montarObjeto(rs));

			}

		} catch (SQLException e) {
			e.printStackTrace();

		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			return lista;
		}

	}

	private T montarObjeto(ResultSet rs) throws IllegalAccessException,
			SQLException, InstantiationException {

		T objectDinamic = clazz.newInstance();

		for (Field field : fields) {
			field.setAccessible(true);
			field.set(objectDinamic, rs.getObject(field.getName()));
		}
		return objectDinamic;
	}

	@SuppressWarnings("finally")
	public T getById(Long id) {

		String sql = String.format("SELECT * FROM %s WHERE id=%d", tableName,id);

		PreparedStatement pstm;
		ResultSet rs;
		T objectDinamic = null;
		try {
			pstm = con.prepareStatement(sql);
			rs = pstm.executeQuery();
			rs.next();
			objectDinamic = montarObjeto(rs);
		} catch (SQLException e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		} finally {
			return objectDinamic;
		}

	}

}

Meu arquivo Main do Flex

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
			   xmlns:s="library://ns.adobe.com/flex/spark" 
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
	<fx:Declarations>
		<mx:RemoteObject id="contato" destination="contato" fault="OnFault(event)">
			<mx:method name="getLista" result="onGetLista(event)"/>
		</mx:RemoteObject>
	</fx:Declarations>
	
	
	<s:creationComplete>
		<![CDATA[
			registerClassAlias("br.com.treinamento.modelo.beans.ContatoVO", br.com.treinamento.modelo.beans.ContatoVO);
			contato.getLista();
		]]>
	</s:creationComplete>
	
	<fx:Script>
		<![CDATA[
			import flash.net.registerClassAlias;
			
			import mx.controls.Alert;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			import br.com.treinamento.modelo.beans.ContatoVO;
			
			protected function onGetLista(event:ResultEvent):void{
				gridContatos.dataProvider=event.result;
			}
			
			protected function OnFault(event:FaultEvent):void{
				Alert.show(event.fault.message.toString());
			}
		]]>
	</fx:Script>
	
	<mx:DataGrid id="gridContatos" x="57" y="67" width="489" height="175">
		<mx:columns>
			<mx:DataGridColumn headerText="id" dataField="id"/>
			<mx:DataGridColumn headerText="Nome" dataField="Nome"/>
			<mx:DataGridColumn headerText="Telefone" dataField="Telefone"/>
			<mx:DataGridColumn headerText="Email" dataField="Email"/>		
		</mx:columns>
	</mx:DataGrid>

	
	
</s:Application>

O arquivo remoting-config.xml

[code]<?xml version="1.0" encoding="UTF-8"?>

<adapters>
    <adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
</adapters>

<default-channels>
    <channel ref="my-amf"/>
</default-channels>

<destination id="contato">
	<properties>
		<source>br.com.treinamento.modelo.dao.ContatoDAO</source>
	</properties>
</destination>

[/code]

Estou usando o JBoss6 e o BlazeDS para comunicação entre as duas plataformas.

O driver do MySql está presente no server/default/lib do jboss

Serei grato mediante qualquer ajuda. :smiley:

Obrigado

Verifique o remoting-config e depois debugue o java.

Bom dia. Obrigado Bruno.

Quando debuguei deu erro aqui (código Flex)

O estranho é que quando executo a aplicação no console mostra

[[quote]09:32:43,741 ERROR [STDERR] java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306/agenda

09:32:43,741 ERROR [STDERR] at java.sql.DriverManager.getConnection(DriverManager.java:602)

09:32:43,741 ERROR [STDERR] at java.sql.DriverManager.getConnection(DriverManager.java:185)

09:32:43,741 ERROR [STDERR] at br.com.treinamento.database.ConnectionFactory.getConnection(ConnectionFactory.java:16)

09:32:43,741 ERROR [STDERR] at br.com.treinamento.modelo.dao.AbstractDAO.(AbstractDAO.java:22)

09:32:43,741 ERROR [STDERR] at br.com.treinamento.modelo.dao.ContatoDAO.(ContatoDAO.java:9)

09:32:43,781 ERROR [STDERR] at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

09:32:43,781 ERROR [STDERR] at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)

09:32:43,781 ERROR [STDERR] at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)

09:32:43,781 ERROR [STDERR] at java.lang.reflect.Constructor.newInstance(Constructor.java:513)

09:32:43,781 ERROR [STDERR] at java.lang.Class.newInstance0(Class.java:355)

09:32:43,781 ERROR [STDERR] at java.lang.Class.newInstance(Class.java:308)

09:32:43,781 ERROR [STDERR] at flex.messaging.util.ClassUtil.createDefaultInstance(ClassUtil.java:110)

09:32:43,791 ERROR [STDERR] at flex.messaging.util.ClassUtil.createDefaultInstance(ClassUtil.java:88)

09:32:43,791 ERROR [STDERR] at flex.messaging.factories.JavaFactoryInstance.createInstance(JavaFactoryInstance.java:99)

09:32:43,791 ERROR [STDERR] at flex.messaging.factories.JavaFactory.lookup(JavaFactory.java:232)

09:32:43,791 ERROR [STDERR] at flex.messaging.FactoryInstance.lookup(FactoryInstance.java:151)

09:32:43,791 ERROR [STDERR] at flex.messaging.services.remoting.adapters.JavaAdapter.createInstance(JavaAdapter.java:487)

09:32:43,791 ERROR [STDERR] at flex.messaging.services.remoting.adapters.JavaAdapter.invoke(JavaAdapter.java:407)

09:32:43,791 ERROR [STDERR] at flex.messaging.services.RemotingService.serviceMessage(RemotingService.java:183)

09:32:43,791 ERROR [STDERR] at flex.messaging.MessageBroker.routeMessageToService(MessageBroker.java:1400)

09:32:43,791 ERROR [STDERR] at flex.messaging.endpoints.AbstractEndpoint.serviceMessage(AbstractEndpoint.java:1005)

09:32:43,811 ERROR [STDERR] at flex.messaging.endpoints.amf.MessageBrokerFilter.invoke(MessageBrokerFilter.java:103)

09:32:43,811 ERROR [STDERR] at flex.messaging.endpoints.amf.LegacyFilter.invoke(LegacyFilter.java:158)

09:32:43,811 ERROR [STDERR] at flex.messaging.endpoints.amf.SessionFilter.invoke(SessionFilter.java:44)

09:32:43,811 ERROR [STDERR] at flex.messaging.endpoints.amf.BatchProcessFilter.invoke(BatchProcessFilter.java:67)

09:32:43,811 ERROR [STDERR] at flex.messaging.endpoints.amf.SerializationFilter.invoke(SerializationFilter.java:166)

09:32:43,831 ERROR [STDERR] at flex.messaging.endpoints.BaseHTTPEndpoint.service(BaseHTTPEndpoint.java:291)

09:32:43,831 ERROR [STDERR] at flex.messaging.MessageBrokerServlet.service(MessageBrokerServlet.java:353)

09:32:43,831 ERROR [STDERR] at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

09:32:43,831 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324)

09:32:43,831 ERROR [STDERR] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)

09:32:43,851 ERROR [STDERR] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)

09:32:43,851 ERROR [STDERR] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)

09:32:43,851 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181)

09:32:43,851 ERROR [STDERR] at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285)

09:32:43,851 ERROR [STDERR] at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261)

09:32:43,851 ERROR [STDERR] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88)

09:32:43,851 ERROR [STDERR] at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100)

09:32:43,851 ERROR [STDERR] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)

09:32:43,851 ERROR [STDERR] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

09:32:43,851 ERROR [STDERR] at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)

09:32:43,921 ERROR [STDERR] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

09:32:43,921 ERROR [STDERR] at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53)

09:32:43,921 ERROR [STDERR] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)

09:32:43,921 ERROR [STDERR] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)

09:32:43,921 ERROR [STDERR] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654)

09:32:43,921 ERROR [STDERR] at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)

09:32:43,921 ERROR [STDERR] at java.lang.Thread.run(Thread.java:662)

09:32:49,680 INFO [org.jboss.web.tomcat.service.deployers.TomcatDeployment] deploy, ctxPath=/HelloWorldWithJBoss
[/quote]

O driver do Mysql está no diretório do Jboss server/default/lib

Boa noite,

Consegui fazer com que os dados finalmente fosse exibidos no grid do flex.

Percebi que a ordem dos atributos presentes na classe Java e na classe do Flex deveriam estar iguais (não vi sentido nisso mas tudo bem). Ficou assim portanto:

Classe Contato no java

[code]

public class Contato {

private Long id;
private String nome;
private String email;
private String telefone;

    //getters e setters

}[/code]

Classe ContatoVO no flex

[code]
package br.com.treinamento.modelo.beans
{
[Bindable]
[RemoteClass(alias=“br.com.treinamento.modelo.beans.Contato”)]
public class ContatoVO
{
public var id:int;
public var nome:String;
public var email:String;
public var telefone:String;

	public function ContatoVO()
	{
	}
}

}[/code]

No entanto amigos, o erro

continua sendo exibido, mas só na primeira vez que o arquivo é executado. Quando inicio o Jboss e tento acessar a página, essa mensagem me é retornada, a partir de então tudo funciona normalmente.

Alguém já passou por isso ou teria algo para indicar?

Reinstalei o JBoss e funcionou

Não entendi :roll: mas funcionou :smiley: :smiley: :smiley:

Abraços