QAndroidJniObject::callStaticMethod is returning 0.

  • Hi; I am writing code about call a Java function from C++ but QAndroidJniObject is returning 0 value. (Note: I included QT += androidextras in .pro file).

    // Java Code
    package com.example.classes;
    public class JavaClassExample {
      public static int factorial(int n) {
        return (n > 1) ? n * factorial(n - 1) : 1;
    // C++ Code
    #include <QMessageBox>
    #include <QAndroidJniObject>
    int factorial(int n)
      return QAndroidJniObject::callStaticMethod<jint>(
    QMessageBox::information(this, tr("Factorial"), QString::number(factorial(7)));
    // Output Always -> 0

    I am learning from here. Thanks.

  • Structure of my project and structure notification example of Qt: IMAGE LINK. I put .java file in Other Files directory but Qt example put .java file in Other file/android-sources/src/org/qtproject/example/notification directory. When I clicked Projects -> Build Android APK -> Create Templates button, created is Other files/android (like in image). Can be problem is so?

  • Hi.
    I am working on a quite similar problem, so maybe this could help:

    Double-check your package names, i guess its good when the package name in your AndroidManifest.xml equals the packe in your Java class.
    I was able to call functions from java classes like shown on slide 42 of your posted link (extending with QtActivity -> remember to change your manifest!).

    Best regards

  • @Qojote Thanks. I solved this problem: I put .java file in android/src/com/example/classes directory and it is running. Alright, how can I create src/com/example/classes directory? I do by manuel but this directory do not see in Qt Creator. Actually how can I create this directory from Qt Creator? Thanks.
    If you want to see directories, you must append this command in the .pro file:
    DISTFILES += path/to/directory
    Then close project and open project again.

Log in to reply