Tuesday, March 26, 2013

Re: JavaScriptException during JSNI call: Invoking an instance method on a null instance

Thanks ChrisK,, You've done a smart job.. It is working.

On Tuesday, October 23, 2012 6:53:21 PM UTC+5:30, ChrisK wrote:
There were a few problems here. My first example calls a zero args function but is not formatted correctly.

If you call something like this:

It won't work. It needs the method signature and parameters separated (no args signature doesn't imply no args last time I checked in GWT):

Notice the additional set of brackets. Very briefly mentioned on https://developers.google.com/web-toolkit/doc/latest/DevGuideCodingBasicsJSNI.

For the final code, I ended up passing "this" as a parameter from Java and also wrapping the JS callback function so it ends up looking like this:

  public PlayerImpl() {

  private native void initialiseCallbacks(PlayerImpl impl) /*-{
    $wnd.js_callback = $entry(function() {

I hope that helps.

On Monday, 22 October 2012 15:23:43 UTC+1, Kartik Kaipa wrote:
did you finally get this working.
I am doing the exact same thing
I pass in the instance of the object as a parameter in the function method

Could you post the working code that you have.
Would really apreciate it.


On Tuesday, March 23, 2010 7:31:24 PM UTC+5:30, Olivier Monaco wrote:

For instance method, you need to reference the method from the
instance like "this.@...". Here is my exact code that compile:

private native void installListener()
    var callback = $entry(this.
    $wnd.addEventListener("message", (function(callback, channel) {
        return function(event) {
            callback.call(channel, event);
    })(callback, this), false);;

Sorry, I forgot that...


On 23 mar, 13:58, ChrisK <cknow...@gmail.com> wrote:
> Actually, Olivier's methods work in development mode but don't seem to
> compile with this error:
> "Cannot make an unqualified reference to the instance method callback"
> I've tried the pre-assignment of "this" to "var that" and also an
> argument to the JSNI method passing in my instance. I've tried both of
> these with Olivier's first method as well as the second to avoid
> leaks. All with the same result - working in development mode but not
> when I compile.
> It looks to me as though the compiler doesn't understand the call
> method or the closure correctly. It looks at though it's trying to
> parse the @mypackage.MyClass::MyMethod() and seeing it's an instance
> method so failed (instead of looking at subsequent JavaScript). Of
> course I could quite easily be doing something wrong.
> Thomas - your method compiles fine so I guess I'll use that for now.
> On Mar 23, 10:07 am, ChrisK <cknow...@gmail.com> wrote:
> > Ahhh ok. Sorry for the simple questions but I'm just getting my head
> > around all this. I also have some other methods with arguments and
> > have those working thanks to both of you.
> > On Mar 23, 9:56 am, Olivier Monaco <olivier.mon...@free.fr> wrote:
> > > ChrisK,
> > > On 23 mar, 10:32, ChrisK <cknow...@gmail.com> wrote:
> > > > Thomas - your solution worked from 6 worked but at first I didn't
> > > > include both pairs of brackets after the function call "MyMethod" but
> > > > it turns out they are required. With only one set (i.e. no arguments),
> > > > it just doesn't work. I thought that was legal but maybe not.
> > > Remember that "@mypackage.MyClass::MyMethod()" is a reference to the
> > > function, not a call. The parenthesis allow you to give the full
> > > signature of the method. Java allows two methods to have the same name
> > > but different parameters. GWT needs the "full" signature to find which
> > > method you want to reference, even is there is only one method with
> > > this name.
> > > The second parenthesis are to call the method. If you forgot then, you
> > > just obtain the function object and do nothing with it...
> > > Olivier


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+unsubscribe@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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.

No comments:

Post a Comment