Your Java code looks right.  Can you turn on the logging in flex-enterprise-services.xml and see what’s coming across as a result of the fill call?  It looks like you don’t have an AS class mapping to the Usuario Java class.  I don’t think we require you have it but it might be worth writing one and getting it linked into the MXML app (private var linker:Usuario;) and see if that makes a difference.

 

Matt

 


From: [email protected] [mailto:[email protected]] On Behalf Of mbordallo
Sent: Tuesday, March 14, 2006 1:12 AM
To: [email protected]
Subject: [flexcoders] Error when i try to get information from a dataservice to populate my datagrid

 

Hi, i'm trying to create a dataservice to conect a database with my datagrid, but i get this error


Error: Item requested at index 0 was null and should not have been. Error for service 'usuario'
at mx.data::DataList/http://www.macromedia.com/2005/flex/mx/internal::requestItemAt()
at mx.data::DataList/getItemAt()
at mx.collections::ListCollectionView/getItemAt()
at mx.collections::ListCollectionViewCursor/seek()
at mx.controls.listclasses::ListBase/modelChanged()
at mx.controls::DataGrid/modelChanged()
at flash.events::EventDispatcher/dispatchEvent()
at mx.collections::ListCollectionView/dispatchEvent()
at mx.collections::ListCollectionView/http://www.macromedia.com/2005/flex/mx/internal::reset()
at mx.collections::ListCollectionView/mx.collections:ListCollectionView::listChangeHandler()
at flash.events::EventDispatcher/dispatchEvent()
at mx.data::DataList/http://www.macromedia.com/2005/flex/mx/internal::processSequenceResult()
at C:\dev\enterprise_beta1\frameworks\mx\data\errors\DataServiceError.as$34::DataListRequestResponder/result()
at mx.rpc::AsyncRequest/acknowledge()
at C:\dev\enterprise_beta1\frameworks\libs\framework.swc(mx/core/mx_internal)$35::NetConnectionMessageResponder/result()



I'm using:

  • Windows XP servicepack 2
  • Mozilla Firefox 1.5 (i've also tryed ie, but i get the same error)
  • Flex 2.0 beta 1
  • Flex Enterprise Services 2.0 beta 1
  • Flash Player 8.5 Alpha 3 (build 211)!





ListaUsuarios.mxml

import mx.collections.ArrayCollection;
import mx.data.DataService;

public var ds:DataService;

[Bindable]
public var usuarios:ArrayCollection;

public function initApp()
{
    usuarios = new ArrayCollection();
    ds = new DataService("usuario");
    ds.fill(usuarios);
}




flex-data-service.xml

<service>

<adapters>

<adapter-definition id="actionscript"   class="flex.data.adapters.ASObjectAdapter" default="true"/>
<adapter-definition id="java-dao" class="flex.data.adapters.JavaAdapter"/>

</adapters>

<default-channels>

<channel ref="my-rtmp"/>

</default-channels>

<destination id="usuario">
    <adapter ref="java-dao" />

<properties>

<metadata>

<identity property="idusuario"/>

</metadata>

<network>

<session-timeout>0</session-timeout>
<paging enabled="false" />
<throttle-inbound policy="ERROR" max-frequency="500"/>
<throttle-outbound policy="REPLACE" max-frequency="500"/>
</network>
<server>

<assembler>

<class>usuarios.UsuarioAssembler</class>
<singleton>true</singleton>

</assembler>


<fill-method>

<name>loadUsuarios</name>

</fill-method>

</server>

</properties>
</destination>


</service>



UsuarioAssembler.java

package usuarios;

import java.util.List;

public class UsuarioAssembler
{

public List loadUsuarios()
{

UsuarioDAO dao = new UsuarioDAO();
return dao.getUsuarios();

}


}



UsuarioDAO.java

package usuarios;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.s! ql.Statement;
import java.util.ArrayList;
import java.util.List;

public class UsuarioDAO
{

public List getUsuarios() throws DAOException
{

ArrayList list = new ArrayList();
Connection c = null;
try
{

c = ConexionBD.getConexion();
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT * FROM alumnos ORDER BY nombre");
Usuario usuario;
while (rs.next())
{

usuario = new Usuario();
usuario.setIdUsuario(rs.getString("id_usuario"));
usuario.setPassword(rs.getString("password"));
usuario.setNombre(rs.getString("nombre"));
list.add(usuario);

}

}
catch (SQLException e)
{

e.printStackTrace();
throw new DAOException(e);

}
finally
{

ConexionBD.cerrarConexion(c);

}
return list;

}

}




Everything in java works correctly, but when i try to call it from flex doesn't work.

If anybody can help me, i will be very pleased.
Thanks in advance.


--
Manuel Bordallo
[EMAIL PROTECTED]

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to