I have a JavaScriptObject like this:
@SingleJsoImpl(Test1Impl.class)
public interface Test1
{
double getValue();
void setValue(String Value);
}
public class Test1Impl extends JavaScriptObject implements Test1
{
protected Test1Impl()
{
}
@Override
public final native double getValue()/*-{
return this.Value||(this.Value=0);
}-*/;
@Override
public final native void setValue(String Value)/*-{
this.Value = Value;
}-*/;
}
And I want to use this:
return this.Value||(this.Value=0);
to set default value,but when I test it
public class GWT_Test implements EntryPoint{
public static native void log(Object message)/*-{
console.log(message);
}-*/;
@Override
public void onModuleLoad()
{
Test1 t1=(Test1) Test1Impl.createObject();
log(t1.getValue());
}
}
I got these erros:
com.google.gwt.core.client.JavaScriptException: (null) @com.gwt.test.client.GWT_Test::log(Ljava/lang/Object;)([Java object: java.lang.Double@239824989]): null
at com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:249)
at com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:136)
at com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:576)
at com.google.gwt.dev.shell.ModuleSpace.invokeNativeVoid(ModuleSpace.java:304)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:107)
at com.dsc.gwt.test.client.GWT_Test.log(GWT_Test.java)
at com.dsc.gwt.test.client.GWT_Test.onModuleLoad(GWT_Test.java:51)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
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(Thread.java:744)
So what is the problem here? Or
How to set default value for double type field?
Update:
@Override
public void onModuleLoad()
{
Test1 t1=(Test1) Test1Impl.createObject();
printDouble(t1.getValue());
}
private void printDouble(Double num){
log(num.toString());
}
and this
@Override
public void onModuleLoad()
{
Test1 t1=(Test1) Test1Impl.createObject();
log(Double.toString(t1.getValue()));
}
Worked as I expected,and can anybody explain first line of error messages?
com.google.gwt.core.client.JavaScriptException: (null)@com.gwt.test.client.GWT_Test::log(Ljava/lang/Object;)([Java object: java.lang.Double@239824989]): null