Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Solved Do not see Java class. Why?

    Mobile and Embedded
    2
    3
    234
    Loading More Posts
    • 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.
    • B
      bogong last edited by bogong

      Hello all!

      I am developing very simple application. Default from Qt Quick template within simple Java class:

      package package.test.usingjava_v1;
      
      public class MyJavaClass {
      
          public static int mTest(int inNumber) {
      
      	return inNumber;
          }
      }
      

      in *.pro file

      android {
      
          QT += androidextras
      
          ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android
      
          OTHER_FILES += \
      	android/MyJavaClass.java
      }
      

      in *.cpp

      QAndroidJniEnvironment* oJNIEnvironment = new QAndroidJniEnvironment();
      	jclass oMyJavaClass = oJNIEnvironment->findClass("package/test/usingjava_v1/MyJavaClass");
      	if(oMyJavaClass == NULL) {
      		qDebug() << "MyJavaClass class not found";
      	}
      

      When trying to run see this error:

      W System.err: java.lang.ClassNotFoundException: Didn't find class "package.test.usingjava_v1.MyJavaClass" on path: DexPathList[[zip file "/data/app/~~EJrl74Lo2NDhB_byCekDiw==/org.qtproject.example.UsingJava_v1-R50S85TnRsBibrRodxNU0A==/base.apk"],nativeLibraryDirectories=[/data/app/~~EJrl74Lo2NDhB_byCekDiw==/org.qtproject.example.UsingJava_v1-R50S85TnRsBibrRodxNU0A==/lib/x86, /data/app/~~EJrl74Lo2NDhB_byCekDiw==/org.qtproject.example.UsingJava_v1-R50S85TnRsBibrRodxNU0A==/base.apk!/lib/x86, /system/lib, /system_ext/lib]]
      W System.err: 	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
      W System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
      W System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
      W System.err: 	at org.qtproject.qt5.android.QtNative.startQtApplication(Native Method)
      W System.err: 	at org.qtproject.qt5.android.QtNative$7.run(QtNative.java:620)
      W System.err: 	at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61)
      W System.err: 	at java.lang.Thread.run(Thread.java:923)
      W System.err: java.lang.ClassNotFoundException: Didn't find class "package.test.usingjava_v1.MyJavaClass" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib, /system_ext/lib]]
      W System.err: 	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
      W System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
      W System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
      W System.err: 	at org.qtproject.qt5.android.QtNative.startQtApplication(Native Method)
      W System.err: 	at org.qtproject.qt5.android.QtNative$7.run(QtNative.java:620)
      W System.err: 	at org.qtproject.qt5.android.QtThread$1.run(QtThread.java:61)
      W System.err: 	at java.lang.Thread.run(Thread.java:923)
      

      Why is that? What am I missing?

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @bogong last edited by

        @bogong
        where exactly did you put the java file inside the "$$PWD/android" directory?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        B 1 Reply Last reply Reply Quote 0
        • B
          bogong @raven-worx last edited by

          @raven-worx Solution found there was troubles with class location. It wasn't in ANDROID_PACKAGE_SOURCE_DIR = $$PWD/android/src. Forgotten about src. The example published here https://github.com/ArboreusSystems/arboreus_examples/tree/master/qt/UsingJava

          1 Reply Last reply Reply Quote 0
          • First post
            Last post