Android-runtime: Cannot convert Javascript Object

Created on 8 Dec 2015  ·  12Comments  ·  Source: NativeScript/android-runtime

I'm pretty sure I have the syntax correct here for Java->JS? Am I missing something, or is the framework not handling this properly, or is it just not convertible at all?

http://www.screencast.com/t/EiuWuvk5c1h

if(isInitalized){
            var activity = frameModule.topmost().android.activity;

    debugger;
    //Dies here with com.zendesk.service.ZendeskCallback
    var callback = new com.zendesk.service.ZendeskCallback({
                        onSuccess: function(args){
                            console.log("SUCCESS");
                            debugger;
                        },
                        onError: function(error){
                            console.log("FAILED");
                            debugger;
                        }
                    });
    debugger;
    com.zendesk.sdk.network.impl.ZendeskConfig.INSTANCE.init(activity, 
                                                            account.appId,  
                                                            account.url, 
                                                            account.clientId, 
                                                            callback
                                                         );
question

Most helpful comment

Hi @sitefinitysteve

According Zendesk documentation com.zendesk.service.ZendeskCallback<T> is an abstract class. In your example above you use the syntax for implementing Java interfaces. You have to use extend syntax as follows

var MyZendeskCallback = com.zendesk.service.ZendeskCallback.extend({
    onSuccess: function(args){
        console.log("SUCCESS");
        debugger;
    },
    onError: function(error){
        console.log("FAILED");
        debugger;
    }
});

var callback = new MyZendeskCallback();

All 12 comments

Hi @sitefinitysteve,

Could you give us a link with your project so that we could try and reproduce the problem. Furthermore where do you expect com.zendesk.service.ZendeskCallback to come from. Is there a link to the Zendesk SDK you could link here?

Here's the plugin atm
https://github.com/sitefinitysteve/nativescript-zendesk

Here's the zendesk page
https://developer.zendesk.com/embeddables/docs/android/gettingstarted#connecting-your-app-to-zendesk

If you need credentials shoot me an email and I'll be happy to share
http://www.sitefinitysteve.com/contact

thank you @sitefinitysteve i was able to reproduce it and will investigate the issue

Hi @sitefinitysteve

According Zendesk documentation com.zendesk.service.ZendeskCallback<T> is an abstract class. In your example above you use the syntax for implementing Java interfaces. You have to use extend syntax as follows

var MyZendeskCallback = com.zendesk.service.ZendeskCallback.extend({
    onSuccess: function(args){
        console.log("SUCCESS");
        debugger;
    },
    onError: function(error){
        console.log("FAILED");
        debugger;
    }
});

var callback = new MyZendeskCallback();

Appreciate you looking into it. Honestly I've been over the docs a million times and never would have made that association.

https://docs.nativescript.org/runtimes/android/generator/how-extend-works.html

if you need to create an interface implementation you don't use extend, and if you need to override(extend) functionality of a class you use extend.

@Plamen5kov So there's 2 cases to "extend" a class

  1. Using extend
  2. Not using extend

Is that correct ? I thought somebody from {N} said that extend is not supported in android ?

And what about using :

class xxx extends android.xxx {
}

Hi @x4080,
you can look at the docs to see how to extend a class and how to implement an interface. And here you can see how does extend work.

Thanks for the tip

@Plamen5kov, sorry for asking again, after reading the documentation "how extend works", is it correct that {N} will create java like in the example :

public class android_view_ViewGroup_myFile_l10_c20 extends android.view.ViewGroup {
    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        // populate the arguments list in an array to pass to the JavaScript world
        java.lang.Object[] params = new java.lang.Object[2];
        params[0] = widthMeasureSpec;
        params[1] = heightMeasureSpec;

        // call the associated JavaScript method
        return excuteJavaScriptMethod(this, “onMeasure”, params);
    }

    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        // populate the arguments list in an array to pass to the JavaScript world
        java.lang.Object[] params = new java.lang.Object[5];
        params[0] = changed;
        params[1] = left;
        params[2] = top;
        params[3] = right;
        params[4] = bottom;

        // call the associated JavaScript method
        return excuteJavaScriptMethod(this, “onLayout”, params);
    }   
}

So it means it has to be build with gradle ? Since I use "tns livesync android" and it works without compiling the java (just copying the .js to android)

Or is it just javascript implementation?

Hi @x4080,

  • is it correct that {N} will create java like in the example :
    Yes the file is generated as you described, but it will be generated at run-time by android-binding-generator

In future releases all possible classes that can be generated at build time, will be, but in order for tns livesync android --watch to work properly we always need to be able to generate some java bindings at run-time.

I see, i noticed some performance cost when using old devices. Thanks for your patience

Was this page helpful?
0 / 5 - 0 ratings