Cant use java objects of classes after callback

39 views
Skip to first unread message

Håvard Moås

unread,
Jul 15, 2014, 4:16:49 AM7/15/14
to gwtex...@googlegroups.com
Hi, I have to say that I am amazed of the work that has gone into this project.

So, I have created a class that does RPC's with a server.
I have created a interface (event) that should trigger at a callback. The callback returns a arraylist of objects that I need to use in java-script.

I have @Export 'ed my class that does the callback, and @ExportClosure 'ed my interface class.
Looking into the Getting Started guide (https://code.google.com/p/gwt-exporter/wiki/GettingStarted), everything seems to be working.

My javascript looks something like this :

    var callbackClass = new package.CallbackClass("arg1","arg2");

   pncma.getTimeInfo("arg1",function(s){
        alert(s);
       });
Output :
Alert box with : [package.TimeClass, package.TimeClass]


So, the variable "s" is a arraylist of my classes, thats perfect!
But If I try this:
var callbackClass = new package.CallbackClass("arg1","arg2");

   pncma.getTimeInfo("arg1",function(s){
        console.debug(s.length());
       });

Output:
com.google.gwt.core.client.JavaScriptException: (null) @package.Interface_ExporterImpl::invoke_getTimeInfoEvent(Lcom/google/gwt/core/client/JavaScriptObject;Ljava/util/ArrayList;)([JavaScript object(104), Java object: java.util.ArrayList@1129678442]): null

It does not matter how i treat my "s"-variable inside my function paramtere, I will get this error no matter what. The only thing that is working right now is alerting the variable.

I have also exported the Time object that it is showing me that I get returned from the interface.

Help is much appreciated!
Regards

Manuel Carrasco Moñino

unread,
Jul 15, 2014, 4:45:42 AM7/15/14
to gwtex...@googlegroups.com
On Tue, Jul 15, 2014 at 10:16 AM, Håvard Moås <haav...@gmail.com> wrote:
Hi, I have to say that I am amazed of the work that has gone into this project.

So, I have created a class that does RPC's with a server.
I have created a interface (event) that should trigger at a callback. The callback returns a arraylist of objects that I need to use in java-script.

I have @Export 'ed my class that does the callback, and @ExportClosure 'ed my interface class.
Looking into the Getting Started guide (https://code.google.com/p/gwt-exporter/wiki/GettingStarted), everything seems to be working.

My javascript looks something like this :

    var callbackClass = new package.CallbackClass("arg1","arg2");

   pncma.getTimeInfo("arg1",function(s){
        alert(s);
       });
Output :
Alert box with : [package.TimeClass, package.TimeClass]


So, the variable "s" is a arraylist of my classes, thats perfect!

's' is not a javascript array, but a java-arraylist, since ArrayList is not an exported class you cannot handle it easily in js.
You have to return a primitive java array instead of an ArrayList object.


gwt-exporter does not support collections 


- Manolo

 
But If I try this:
var callbackClass = new package.CallbackClass("arg1","arg2");

   pncma.getTimeInfo("arg1",function(s){
        console.debug(s.length());
       });

Output:
com.google.gwt.core.client.JavaScriptException: (null) @package.Interface_ExporterImpl::invoke_getTimeInfoEvent(Lcom/google/gwt/core/client/JavaScriptObject;Ljava/util/ArrayList;)([JavaScript object(104), Java object: java.util.ArrayList@1129678442]): null

It does not matter how i treat my "s"-variable inside my function paramtere, I will get this error no matter what. The only thing that is working right now is alerting the variable.

I have also exported the Time object that it is showing me that I get returned from the interface.

Help is much appreciated!
Regards

--
Has recibido este mensaje porque estás suscrito al grupo "gwtexporter" de Grupos de Google.
Para anular la suscripción a este grupo y dejar de recibir sus mensajes, envía un correo electrónico a gwtexporter...@googlegroups.com.
Para acceder a más opciones, visita https://groups.google.com/d/optout.

Message has been deleted

Håvard Moås

unread,
Jul 15, 2014, 7:24:55 AM7/15/14
to gwtex...@googlegroups.com
I just converted my arraylist to a primitiv java array.
ArrayList<Time> is now Time[].

But I still get a very simmular exception thrown but now it says that Time is null. Time is exportable

Regards

Manuel Carrasco Moñino

unread,
Jul 16, 2014, 1:56:26 AM7/16/14
to gwtex...@googlegroups.com
I have arrays of exportable working fine, but It could be a bug in the library. Could you post a very simple example without any complex dependency so as I can check the issue?

- Manolo


Håvard Moås

unread,
Jul 16, 2014, 2:16:25 AM7/16/14
to gwtex...@googlegroups.com
Here is a non-complex way of my system


the class callbackevent should return array of:

@Export
@ExportPackage("package")
public class time implement Exportable{
public int arg1;
public int arg2;

public time(int arg1, int arg2){
this.arg1=arg1;
this.arg2=arg2;
}
}

interface:
@Export
@ExportPackage("package")
public Interface callbackEvent extends Exportable{

public void getTimeInfoEvent(Time[] info);
}

callback class:
@Export
@ExportPackage("package")
public class callback implement Exportable{

public callback(){};

public void getTimeInfo(Interface interface){
//Do something = time[] info;
interface.getTimeInfo(info);
}
}

javascript that uses callback class:
var callback = package.callback();
callback.getTimeInfo(function(a){
console.debug(a);            //This gets me a nullpointer
a.length                          //This also gets me a nullpoint
});
Reply all
Reply to author
Forward
0 new messages