Important: Please read the 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 Method)
    W/System.err(15479): at$
    W/System.err(15479): at$
    W/System.err(15479): at

    Here is my Java code :

    C++ call :

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


  • 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



  • 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