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

How to handle the situation when Java method being called via JNI does not exist?



  • If I call a Java method that does not exist with a code like this:

    QAndroidJniEnvironment javaEnv;
    QAndroidJniObject javaAd(QtAndroid::androidActivity());
    
    javaAd.callMethod<void>("aWrongMethodName");
    
    if (javaEnv->ExceptionCheck())
    {
        javaEnv->ExceptionClear();
    
        qDebug() << " Java code has thrown an exception.";
    }
    
    

    javaAd.callMethod executes successfully, and javaEnv->ExceptionCheck() returns false, so it is not clear how to handle the situation when Java method being called does not exist.

    Is there a way to make javaAd.callMethod throw an exception or set some error flag in such a case?


Log in to reply