setNdefPushMessageCallback的GetMethodID失败

时间:2015-08-20 02:19:11

标签: android java-native-interface nfc

我试图在JNI图层中设置setNdefPushMessageCallback。 为此,我将获得此方法ID:

public void  setNdefPushMessageCallback (NfcAdapter.CreateNdefMessageCallback callback, Activity activity, Activity... activities) 

这是我的代码:

jmethodID methodId = (*env)->GetMethodID(
        env, cls, "setNdefPushMessageCallback",
        "(Landroid/nfc/NfcAdapter/CreateNdefMessageCallback;[Landroid/app/Activity;)V;");

我也尝试过只给Landroid/app/Activity;。但我得到java.lang.NoSuchMethodError例外。请帮帮我在这种情况下我将使用的签名是什么?

08-20 11:02:01.451: E/AndroidRuntime(24550): FATAL EXCEPTION: main
08-20 11:02:01.451: E/AndroidRuntime(24550): Process: org.iotivity.ca.sample_service, PID: 24550
08-20 11:02:01.451: E/AndroidRuntime(24550): java.lang.NoSuchMethodError: no non-static method "Landroid/nfc/NfcAdapter;.setNdefPushMessageCallback(Landroid/nfc/NfcAdapter/CreateNdefMessageCallback;[Landroid/app/Activity;)V;"

1 个答案:

答案 0 :(得分:1)

您对第一个参数使用了错误的签名:

CreateNdefMessageCallbackNfcAdapter的内部类。

Landroid/nfc/NfcAdapter/CreateNdefMessageCallback替换为Landroid/nfc/NfcAdapter$CreateNdefMessageCallback

编辑:
的对应签名 public void setNdefPushMessageCallback (NfcAdapter.CreateNdefMessageCallback callback, Activity activity, Activity... activities)

(Landroid/nfc/NfcAdapter$CreateNdefMessageCallback;Landroid/app/Activity;[Landroid/app/Activity;)V