Extending Activity crash app


#1

Hello,

I am trying to follow this library: https://github.com/mayubao/Android-Pay#about-wechat-pay-callback

my activity.android.ts

import {setActivityCallbacks, AndroidActivityCallbacks} from "ui/frame";
import * as app from "application";

@JavaProxy("com.myapp.MainActivity")
class WXPayEntryActivity extends android.app.Activity implements IWXAPIEventHandler{
    private _callbacks: AndroidActivityCallbacks;
    private static TAG = "MicroMsg.SDKSample.WXPayEntryActivity";
    private api;
    private APP_ID = "appid78";

    protected onCreate(savedInstanceState: android.os.Bundle): void {
        if (!this._callbacks) {
            setActivityCallbacks(this);
        }

        this._callbacks.onCreate(this, savedInstanceState, super.onCreate);
        console.log("started !!")
        this.api = com.tencent.mm.sdk.openapi.WXAPIFactory.createWXAPI(this, this.APP_ID);
        this.api.handleIntent(android.content.Intent.getIntent(), this);

    }
   
}

Error:

An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.test/com.myapp.MainActivity}: com.tns.NativeScriptException: 
Calling js method onCreate failed

Error: java.lang.Exception: Failed resolving method getIntent on class android.content.Intent
    com.tns.Runtime.resolveMethodOverload(Runtime.java:1004)
    com.tns.Runtime.callJSMethodNative(Native Method)
    com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
    com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
    com.tns.Runtime.callJSMethod(Runtime.java:912)
    com.tns.Runtime.callJSMethod(Runtime.java:896)
    com.tns.Runtime.callJSMethod(Runtime.java:888)
    com.moodle.MainActivity.onCreate(MainActivity.java:13)
    android.app.Activity.performCreate(Activity.java:6904)
    android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
    android.app.ActivityThread.access$1100(ActivityThread.java:229)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
    android.os.Handler.dispatchMessage(Handler.java:102)
    android.os.Looper.loop(Looper.java:148)
    android.app.ActivityThread.main(ActivityThread.java:7325)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
File: "file:///data/data/com.moodle.snmandarin/files/app/activity.js, line: 18, column: 53

StackTrace: 
	Frame: function:'WXPayEntryActivity.onCreate', file:'file:///data/data/com.myapp.test/files/app/activity.js', line: 18, column: 54


	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
	at android.app.ActivityThread.access$1100(ActivityThread.java:229)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:148)
	at android.app.ActivityThread.main(ActivityThread.java:7325)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: com.tns.NativeScriptException: 
Calling js method onCreate failed

Error: java.lang.Exception: Failed resolving method getIntent on class android.content.Intent
    com.tns.Runtime.resolveMethodOverload(Runtime.java:1004)
    com.tns.Runtime.callJSMethodNative(Native Method)
    com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
    com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
    com.tns.Runtime.callJSMethod(Runtime.java:912)
    com.tns.Runtime.callJSMethod(Runtime.java:896)
    com.tns.Runtime.callJSMethod(Runtime.java:888)
    com.moodle.MainActivity.onCreate(MainActivity.java:13)
    android.app.Activity.performCreate(Activity.java:6904)
    android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
    android.app.ActivityThread.access$1100(ActivityThread.java:229)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
    android.os.Handler.dispatchMessage(Handler.java:102)
    android.os.Looper.loop(Looper.java:148)
    android.app.ActivityThread.main(ActivityThread.java:7325)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
File: "file:///data/data/com.moodle.snmandarin/files/app/activity.js, line: 18, column: 53

StackTrace: 
	Frame: function:'WXPayEntryActivity.onCreate', file:'file:///data/data/com.moodle.snmandarin/files/app/activity.js', line: 18, column: 54


	at com.tns.Runtime.callJSMethodNative(Native Method)
	at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
	at com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
	at com.tns.Runtime.callJSMethod(Runtime.java:912)
	at com.tns.Runtime.callJSMethod(Runtime.java:896)
	at com.tns.Runtime.callJSMethod(Runtime.java:888)
	at com.moodle.MainActivity.onCreate(MainActivity.java:13)
	at android.app.Activity.performCreate(Activity.java:6904)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
	... 9 more
Caused by: java.lang.Exception: Failed resolving method getIntent on class android.content.Intent
	at com.tns.Runtime.resolveMethodOverload(Runtime.java:1004)
	... 19 more

Any suggestion please? Thanks in advance.


#2

if you pay close attention, you will see that getIntent() is called on the Activity class, the this is implicit, and that’s why it’s not present in the Java code. Therefore I believe that line should be this.getIntent().

Here’s a link to the Android reference - https://developer.android.com/reference/android/app/Activity.html#getIntent()


#3

Thanks for your reply. I tried like this now:

this.api.handleIntent(this.getIntent(), this);

But error:

An uncaught Exception occurred on "main" thread.
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.test/com.myapp.MainActivity}: com.tns.NativeScriptException: 
Calling js method onCreate failed

Error: java.lang.Exception: Failed resolving method handleIntent on class com.tencent.mm.sdk.openapi.WXApiImplV10
    com.tns.Runtime.resolveMethodOverload(Runtime.java:1004)
    com.tns.Runtime.callJSMethodNative(Native Method)
    com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
    com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
    com.tns.Runtime.callJSMethod(Runtime.java:912)
    com.tns.Runtime.callJSMethod(Runtime.java:896)
    com.tns.Runtime.callJSMethod(Runtime.java:888)
    com.moodle.MainActivity.onCreate(MainActivity.java:13)
    android.app.Activity.performCreate(Activity.java:6904)
    android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
    android.app.ActivityThread.access$1100(ActivityThread.java:229)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
    android.os.Handler.dispatchMessage(Handler.java:102)
    android.os.Looper.loop(Looper.java:148)
    android.app.ActivityThread.main(ActivityThread.java:7325)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
File: "file:///data/data/com.myapp.test/files/app/activity.js, line: 18, column: 17

StackTrace: 
	Frame: function:'WXPayEntryActivity.onCreate', file:'file:///data/data/com.myapp.test/files/app/activity.js', line: 18, column: 18


	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3319)
	at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
	at android.app.ActivityThread.access$1100(ActivityThread.java:229)
	at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
	at android.os.Handler.dispatchMessage(Handler.java:102)
	at android.os.Looper.loop(Looper.java:148)
	at android.app.ActivityThread.main(ActivityThread.java:7325)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
Caused by: com.tns.NativeScriptException: 
Calling js method onCreate failed

Error: java.lang.Exception: Failed resolving method handleIntent on class com.tencent.mm.sdk.openapi.WXApiImplV10
    com.tns.Runtime.resolveMethodOverload(Runtime.java:1004)
    com.tns.Runtime.callJSMethodNative(Native Method)
    com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
    com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
    com.tns.Runtime.callJSMethod(Runtime.java:912)
    com.tns.Runtime.callJSMethod(Runtime.java:896)
    com.tns.Runtime.callJSMethod(Runtime.java:888)
    com.moodle.MainActivity.onCreate(MainActivity.java:13)
    android.app.Activity.performCreate(Activity.java:6904)
    android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
    android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
    android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3415)
    android.app.ActivityThread.access$1100(ActivityThread.java:229)
    android.app.ActivityThread$H.handleMessage(ActivityThread.java:1821)
    android.os.Handler.dispatchMessage(Handler.java:102)
    android.os.Looper.loop(Looper.java:148)
    android.app.ActivityThread.main(ActivityThread.java:7325)
    java.lang.reflect.Method.invoke(Native Method)
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
File: "file:///data/data/com.moodle.snmandarin/files/app/activity.js, line: 18, column: 17

StackTrace: 
	Frame: function:'WXPayEntryActivity.onCreate', file:'file:///data/data/com.myapp.test/files/app/activity.js', line: 18, column: 18


	at com.tns.Runtime.callJSMethodNative(Native Method)
	at com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1043)
	at com.tns.Runtime.callJSMethodImpl(Runtime.java:925)
	at com.tns.Runtime.callJSMethod(Runtime.java:912)
	at com.tns.Runtime.callJSMethod(Runtime.java:896)
	at com.tns.Runtime.callJSMethod(Runtime.java:888)
	at com.moodle.MainActivity.onCreate(MainActivity.java:13)
	at android.app.Activity.performCreate(Activity.java:6904)
	at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1136)
	at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3266)
	... 9 more
Caused by: java.lang.Exception: Failed resolving method handleIntent on class com.tencent.mm.sdk.openapi.WXApiImplV10
	at com.tns.Runtime.resolveMethodOverload(Runtime.java:1004)
	... 19 more


#4

@Pete.K, any other suggestion? I am still stuck there :frowning:

Error: java.lang.Exception: Failed resolving method handleIntent on class com.tencent.mm.sdk.openapi.WXApiImplV10