Hi,

*I tried to post this here a week before, but for whatever reason I posted 
it in another group...Now, after waiting one week for the post to be 
activated by a moderator I found it with a google search in another group 
(GWT Contributors). Maybe it was wrongly attached by a moderator to that 
other group?!? Doesn't matter. I only write it down in case that happens 
again. *


*I got an answer that my function TestObj.member1 has to return 'this'. I'm 
still new to JavaScript but I think a call of new TestObj.member1 should 
return the object that is created?!Here is the original posting. I hope it 
works now...thanks a lot!!:*

I am trying to find a bug in my first gwt project. I wrote another little 
project with just 3 classes to show just the behavior I don't understand.
I try to initialize objects in JavaScript (need that to use an existing js 
script in my (new) Java Code).

For my test I simply want to get an Object with a number array and read 
that...but the call of get(i) leads to 'Something other than a double was 
returned from JSNI method'.

Can anybody point me in the right direction please!?

Thanks a lot!! :)

JavaScript:
var TestObj = {};

/* helper function to get such an object
 * not possible to get it directly?!*/
function getMem1(x,y){
return new TestObj.member1([x,y]);
}

TestObj.member1 = function(p){
// should be an array of two floating point values (saved as double in java)
this.p = p;
}

My Java Object:
public class TestObjJava {

private double x;
private double y;
 public TestObjJava(double x, double y) {
this.x = x;
this.y = y;
}

public native TestObjJS getAsJSObj() /*-{
return $wnd.getMem1(this.x, this.y)
}-*/;
}

My JavaScriptObject
public class TestObjJS extends JavaScriptObject {

protected TestObjJS() {}

public final native JsArrayNumber getP() /*-{ return this.p; }-*/;
}

The code that leads to the error:
public void onModuleLoad() {
 TestObjJava jObj = new TestObjJava(12, 23);
TestObjJS jsObj = jObj.getAsJSObj();
 JsArrayNumber p = jsObj.getP();
 System.out.println(p);
 for(int i=0; i<p.length(); i++){
System.out.println(i+": "+p.get(i));
}
}

The full error message:

onModuleLoad() threw an exception
Exception while loading module andymel.tests.gwttests.client.GWTTests. See 
Development Mode for details.


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.google.gwt.dev.shell.ModuleSpace.onLoad(ModuleSpace.java:411)
at 
com.google.gwt.dev.shell.OophmSessionHandler.loadModule(OophmSessionHandler.java:200)
at 
com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:526)
at 
com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:364)
at java.lang.Thread.run(Unknown Source)
Caused by: com.google.gwt.dev.shell.HostedModeException: Something other 
than a double was returned from JSNI method 
'@com.google.gwt.core.client.JsArrayNumber::get(I)': JS value of type 
undefined, expected double
at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:112)
at 
com.google.gwt.dev.shell.ModuleSpace.invokeNativeDouble(ModuleSpace.java:238)
at 
com.google.gwt.dev.shell.JavaScriptHost.invokeNativeDouble(JavaScriptHost.java:59)
at com.google.gwt.core.client.JsArrayNumber$.get$(JsArrayNumber.java)
at andymel.tests.gwttests.client.GWTTests.onModuleLoad(GWTTests.java:30)
... 9 more

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

Reply via email to