jibon57 jibon57 - 1 month ago 12
Android Question

NativeScript Android error: java.lang.Object com.tns.Runtime.callJSMethodNative

I am trying to add a payment library (https://github.com/mayubao/Android-Pay) for android like this:

let activity = utils.ad.getApplicationContext();
let d = new Date().getMilliseconds();
let time = d.toString()

let wechatPayReq = new io.github.mayubao.pay_library.WechatPayReq.Builder()
.with(activity) //activity instance
.setAppId('wxd930ea5d5a258f4f') //wechat pay AppID
.setPartnerId("1900000109")//wechat pay partner id
.setPrepayId("1101000000140415649af9fc314aa427")//pre pay id
.setNonceStr("1101000000140429eb40476f8896f4c9")
.setTimeStamp(time)//time stamp
.setSign("7FFECB600D7157C5AA49810D2D8F28BC2811827B")//sign
.create();
//2. send the request with wechat pay
io.github.mayubao.pay_library.PayAPI.getInstance().sendPayRequest(wechatPayReq);


But I am getting following error:

08-19 10:40:50.627 4706 4706 F art : art/runtime/java_vm_ext.cc:470] from java.lang.Object com.tns.Runtime.callJSMethodNative(int, int, java.lang.String, int, boolean, java.lang.Object[])
08-19 10:40:50.627 4706 4706 F art : art/runtime/java_vm_ext.cc:470] at com.tns.Runtime.callJSMethodNative(Native method)
08-19 10:40:50.627 4706 4706 F art : art/runtime/java_vm_ext.cc:470] at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
08-19 10:40:50.627 4706 4706 F art : art/runtime/java_vm_ext.cc:470] at com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
08-19 10:40:50.627 4706 4706 F art : art/runtime/java_vm_ext.cc:470] at com.tns.Runtime.callJSMethod(Runtime.java:912)
08-19 10:40:50.627 4706 4706 F art : art/runtime/java_vm_ext.cc:470] at com.tns.Runtime.callJSMethod(Runtime.java:896)
08-19 10:40:50.627 4706 4706 F art : art/runtime/java_vm_ext.cc:470] at com.tns.Runtime.callJSMethod(Runtime.java:888)
08-19 10:40:50.695 4706 4706 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethodNative(Native method)
08-19 10:40:50.695 4706 4706 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
08-19 10:40:50.696 4706 4706 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
08-19 10:40:50.696 4706 4706 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethod(Runtime.java:912)
08-19 10:40:50.696 4706 4706 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethod(Runtime.java:896)
08-19 10:40:50.696 4706 4706 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethod(Runtime.java:888)
08-19 10:40:50.698 4706 4706 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethodNative(Native method)
08-19 10:40:50.698 4706 4706 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
08-19 10:40:50.698 4706 4706 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
08-19 10:40:50.698 4706 4706 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethod(Runtime.java:912)
08-19 10:40:50.698 4706 4706 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethod(Runtime.java:896)
08-19 10:40:50.698 4706 4706 F art : art/runtime/runtime.cc:403] at com.tns.Runtime.callJSMethod(Runtime.java:888)


Environement:

tns --version
3.1.3

"tns-android": {
"version": "3.1.1"
}


In where I am doing wrong? Please advice me. Thanks in advance.

Answer Source

I was trying to pass ApplicationContext instated of Activity. So the solution is:

import * as app from 'application';    
let activity = app.android.foregroundActivity;

Also make sure that wechat app is install in device.