Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Problem using context and JNI



  • Hello,

    I would like to do an Android app using FTDI Java library and Qt.
    Firstly, because I found easier to code in Java, I did my app on Android Studio and it works well.
    FTDI methods use application context as argument : 0_1556619455603_d6c28dfc-5c7b-4f83-a142-b7358398789d-image.png

    Now I'm trying to do the same app on Qt Creator.
    As a simple example, I'm just trying to call a Java method (that uses application context) from C++ using JNI.

    The problem is I'm getting this error and I don't know how to solve it :

    W/System.err(15479): java.lang.NoSuchMethodError: no static method "Lcom/ftdi/d2xxjava/MyApplication;.testStatic(I, Landroid/content/Context)V"
    W/System.err(15479): at org.qtproject.qt5.android.QtNative.startQtApplication(Native Method)
    W/System.err(15479): at org.qtproject.qt5.android.QtNative$6.run(QtNative.java:365)
    W/System.err(15479): at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61)
    W/System.err(15479): at java.lang.Thread.run(Thread.java:818)

    Here is my Java code :
    0_1556619776942_fc08a8c5-0cd9-4dda-a3ab-a42753c6e9c3-image.png

    C++ call :
    0_1556619910740_c03d51f0-fcc5-46d4-8cbc-34ee3b3930c3-image.png

    "MyApplication" Class doesn't extend QtActivity, can it be the problem?
    If I do so, I get an other error :

    F/art (17395): sart/runtime/check_jni.cc:65] JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception 'java.lang.RuntimeException' thrown in unknown throw location
    F/art (17395): sart/runtime/check_jni.cc:65] in call to GetMethodID
    F/art (17395): sart/runtime/check_jni.cc:65] from void org.qtproject.qt5.android.QtNative.startQtApplication()
    F/art (17395): sart/runtime/check_jni.cc:65] "qtMainLoopThread" prio=5 tid=5 Runnable
    F/art (17395): sart/runtime/check_jni.cc:65] | group="main" sCount=0 dsCount=0 obj=0x12c231c0 self=0xab350fb8
    F/art (17395): sart/runtime/check_jni.cc:65] | sysTid=17471 nice=0 cgrp=default sched=0/0 handle=0xab2dafd0
    F/art (17395): sart/runtime/check_jni.cc:65] | state=R schedstat=( 230849873 94922049 241 ) utm=23 stm=0 core=1 HZ=100
    F/art (17395): sart/runtime/check_jni.cc:65] | stack=0x4c11e000-0x4c120000 stackSize=1036KB
    F/art (17395): sart/runtime/check_jni.cc:65] | held mutexes= "mutator lock"(shared held)
    F/art (17395): sart/runtime/check_jni.cc:65] native: #00 pc 00004e84 /system/lib/libbacktrace_libc++.so (_ZN13UnwindCurrent6UnwindEjP8ucontext+23)
    F/art (17395): sart/runtime/check_jni.cc:65] native: #01 pc 0000369d /system/lib/libbacktrace_libc++.so (_ZN9Backtrace6UnwindEjP8ucontext+8)

    Thanks


  • Moderators

    @Damalo_02 said in Problem using context and JNI:

    (I, Landroid/content/Context)V

    is not a correct JNI signature.
    Correct: (ILandroid/content/Context)V



  • @raven-worx said in Problem using context and JNI:

    Correct: (ILandroid/content/Context)V

    I think you missed a semicolone symbole and it should be (ILandroid/content/Context;)V

    => cf. JNI Types and Data Structures

    Regards

    Fabrice



  • Yes it was a problem of JNI signature, and you're right @KroMignon a semicolon is missing.

    Right signature is : (ILandroid/content/Context;)V

    Thanks a lot for your help


Log in to reply