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. java.lang.ClassNotFoundException when trying basic JNI example
Forum Updated to NodeBB v4.3 + New Features

java.lang.ClassNotFoundException when trying basic JNI example

Scheduled Pinned Locked Moved Solved Mobile and Embedded
4 Posts 3 Posters 2.4k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    Diracsbracket
    wrote on 25 Apr 2018, 17:52 last edited by Diracsbracket
    #1

    Hi,
    I am trying out a basic JNI example (Fibonacci example in https://conf.qtcon.org/system/attachments/132/original/QtCon16.pdf%3F1473147092) but I get the following build error:

    W System.err: java.lang.ClassNotFoundException: Didn't find class "com.example.test.JniTest" on path: DexPathList[[],nativeLibraryDirectories=[/system/lib, /vendor/lib]]
    W System.err: 	at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:125)
    W System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    W System.err: 	at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    D libTestApp: (null):0 ((null)): Fibonacci:  0
    

    I have created the Java file JniTest.java as follows:

    public class JniTest
    {
        public static int fibonacci(int n)
        {
            if(n<0)
                return -1;
            else if(n==0 || n==1)
                return n;
    
            return fibonacci(n-1)+fibonacci(n-2);
        }
    }
    

    The java file is stored as android-source/src/com/example/test/JniTest.java and added to the Qt Creator project.

    In a .cpp file, I have:

    int AndroidInterface::fibonacci(int n)
    {
        return QAndroidJniObject::callStaticMethod<jint>("com/example/test/JniTest"
                                                     , "fibonacci"
                                                     , "(I)I"
                                                     , n);
    }
    

    and in my main.cpp:

      AndroidInterface android;
      ...
      qDebug() << "Fibonacci: " << android.fibonacci(3);
      ...
       return app.exec();
    

    However, this results in the errors shown above. Why?
    Tried it on Qt 5.10.1, on a virtual Android device.

    1 Reply Last reply
    0
    • P Offline
      P Offline
      Pablo J. Rogina
      wrote on 25 Apr 2018, 20:04 last edited by Pablo J. Rogina
      #2

      @Diracsbracket if JniTest.java source code is completely displayed in the post, it looks to me that you're missing 'package' (see slide 34 from your reference):

      package com.example.test;
      

      Upvote the answer(s) that helped you solve the issue
      Use "Topic Tools" button to mark your post as Solved
      Add screenshots via postimage.org
      Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

      D 1 Reply Last reply 26 Apr 2018, 03:29
      3
      • P Pablo J. Rogina
        25 Apr 2018, 20:04

        @Diracsbracket if JniTest.java source code is completely displayed in the post, it looks to me that you're missing 'package' (see slide 34 from your reference):

        package com.example.test;
        
        D Offline
        D Offline
        Diracsbracket
        wrote on 26 Apr 2018, 03:29 last edited by Diracsbracket
        #3

        @Pablo-J.-Rogina said in java.lang.ClassNotFoundException when trying basic JNI example:

        it looks to me that you're missing 'package'

        You're absolutely right!
        This is a little bit embarrassing... "They have eyes, yet they don't see...".

        Thank you for your kind help, and for a good lesson learned. I'll never again forget
        to put the package declaration at the top of a Java file...

        1 Reply Last reply
        1
        • S Offline
          S Offline
          Surajkumar Tanurkar
          wrote on 17 Apr 2020, 13:24 last edited by
          #4

          i am also getting same error my signal and slot working well but class not found exception error is there
          i have declared package name in java file in manifest file too
          Screenshot 2020-04-17 at 6.52.59 PM.png Screenshot 2020-04-17 at 6.52.37 PM.png

          1 Reply Last reply
          0

          • Login

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