1

I am working on a NativeScript Stripe plugin, using TypeScript. It's working on iOS, now trying to get it working on Android.

I have been able to successfully extend some Android classes (following Extending Classes). One, though, gives ClassNotFoundException when it is being constructed.

I created a .d.ts file using android-dts-generator. It gives the signature of the class I'm extending as (abbreviated):

declare module com {
  export module stripe {
    export module android {
      export class PaymentSession {
        export class PaymentSessionListener {
          public constructor();
          public onError(param0: number, param1: string): void;
          ...
        }}}}}

I extend as follows:

class InternalPaymentListener extends com.stripe.android.PaymentSession.PaymentSessionListener {
  constructor() {
    super();
    return global.__native(this);
  }
  init(p1, p2): InternalPaymentListener { ...; return this; }
  ...
}

When I try to construct this, using new InternalPaymentListener().init(p1, p2) I get a ClassNotFoundException:

JS: ERROR Error: java.lang.ClassNotFoundException: com.tns.gen.com.stripe.android.PaymentSession_PaymentSessionListener_stripe_148_28_InternalPaymentListener
JS:     java.lang.Class.classForName(Native Method)
JS:     java.lang.Class.forName(Class.java:453)
JS:     java.lang.Class.forName(Class.java:378)
JS:     com.tns.Runtime.getClassForName(Runtime.java:1023)
JS:     com.tns.ClassResolver.resolveClass(ClassResolver.java:27)
JS:     com.tns.Runtime.resolveClass(Runtime.java:593)
JS:     com.tns.Runtime.callJSMethodNative(Native Method)
JS:     com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1101)
JS:     com.tns.Runtime.callJSMethodImpl(Runtime.java:983)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:970)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:954)
JS:     com.tns.Runtime.callJSMethod(Runtime.java:946)
JS:     com.tns.gen.java.lang.Object_button_19_32_ClickListenerImpl.onClick(Object_button_19_32_ClickListenerImpl.java:17)
JS:     android.view.View.performClick(View.java:6294)
JS:     android.view.View$PerformClick.run(View.java:24770)
JS:     android....

The generated stripe.js file has at line 148 (which I assume is what the exception is pointing me to):

function InternalPaymentListener() {
    var _this = _super.call(this) || this;    <-- Line 148
    return global.__native(_this);
}

The code compiles without error or warning, so you'd think the class got generated properly. It runs until I click the button that results in this class being constructed.

Any ideas how to resolve this?

1 Answer 1

1

Looks like I found the answer to my own question, so quickly I'm almost embarrassed for asking in the first place!

It turns out PaymentSessionListener is an interface, not a class. I was confused by the .d.ts definition generated by android-dts-generator. This is how to correctly implement the interface (as documented at Extending Classes):

function createListener() {
  return new com.stripe.android.PaymentSession.PaymentSessionListener({
    onError(param0: number, param1: string): void { ... }
    ...
  });
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.