Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QAndroidJniObject::callStaticMethod is returning 0.
Forum Update on Monday, May 27th 2025

QAndroidJniObject::callStaticMethod is returning 0.

Scheduled Pinned Locked Moved Solved Mobile and Embedded
4 Posts 2 Posters 1.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Ibrahim
    wrote on 23 Feb 2016, 14:01 last edited by
    #1

    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>(
            "com/example/classes/JavaClassExample",
            "factorial",
            "(I)I",
            n);
    }
    ...
    QMessageBox::information(this, tr("Factorial"), QString::number(factorial(7)));
    // Output Always -> 0
    

    I am learning from here. Thanks.

    1 Reply Last reply
    0
    • I Offline
      I Offline
      Ibrahim
      wrote on 24 Feb 2016, 11:45 last edited by
      #2

      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?

      1 Reply Last reply
      0
      • Q Offline
        Q Offline
        Qojote
        wrote on 24 Feb 2016, 13:05 last edited by
        #3

        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

        I 1 Reply Last reply 24 Feb 2016, 16:00
        1
        • Q Qojote
          24 Feb 2016, 13:05

          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

          I Offline
          I Offline
          Ibrahim
          wrote on 24 Feb 2016, 16:00 last edited by Ibrahim
          #4

          @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.
          Edit:
          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.

          1 Reply Last reply
          0

          1/4

          23 Feb 2016, 14:01

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved