Qt World Summit: Submit your Presentation

JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception java.lang.RuntimeException

  • Hi All,
    I want to build an app using C++ and Java by JNI in the platform of Qt, I tried to do the code below: c++

    #include "musiclist.h"
    #include <QAndroidIntent>
    #include <QAndroidJniEnvironment>
    #include <QDebug>
    #include <QStringList>
    #include <QNetworkReply>
    MusicTrack::MusicTrack(QObject *parent) : QObject(parent){}
    void MusicTrack::testerJava()
        QNetworkAccessManager *manager = new QNetworkAccessManager();
          //QAndroidJniObject java("org/qtproject/example/musiclist/MusicList");
         // jint res = java.callMethod<jint>("createAp","(Landroid/content/Context)I",QtAndroid::androidContext().object());
          if (QAndroidJniObject::isClassAvailable("org/qtproject/example/musiclist/MusicList")){
              qDebug()<<"Classe trouvé";
              QAndroidJniEnvironment env;
              jclass javaClass = env.findClass("org/qtproject/example/musiclist/MusicList");
              QAndroidJniObject classObject(javaClass);

    Java code:

    import android.os.Bundle;
    import android.widget.TextView;
    import android.net.*;
    import android.net.wifi.WifiManager;
    import android.net.wifi.*;
    import  android.net.ConnectivityManager;
    import  android.net.wifi.WifiInfo;
    import android.net.NetworkInfo.DetailedState;
    import android.net.DhcpInfo;
    import  android.net.nsd.NsdManager;
    import android.net.nsd.NsdManager.DiscoveryListener;
    import android.util.Log;
    import android.net.nsd.NsdServiceInfo;
    import android.text.format.Formatter;
    import java.net.NetworkInterface;
    import java.net.SocketException;
    import java.util.Enumeration;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    import java.net.InetAddress;
    import  java.io.IOException;
    import  java.net.UnknownHostException;
    //import android.app.Activity;
    import java.lang.reflect.Method;
     public  class MusicList extends org.qtproject.qt5.android.bindings.QtActivity {
         final String TAG="Display Message";
         final String SERVICE_TYPE="_http._tcp.";
         final  String serviceName= "esp32";
          private  NsdManager.DiscoveryListener  discoveryListener;
          private  NsdManager nsdManager;
          //Context context;
         public void initializeDiscoveryListener() {
             // Instantiate a new DiscoveryListener
               discoveryListener = new NsdManager.DiscoveryListener() {
                 // Called as soon as service discovery begins.
                 public void onDiscoveryStarted(String regType) {
                     Log.d(TAG, "Service discovery started");
                 public void onServiceFound(NsdServiceInfo service) {
                     // A service was found! Do something with it.
                     Log.d(TAG, "Service discovery success" + service);
                     if (!service.getServiceType().equals(SERVICE_TYPE)) {
                         // Service type is the string containing the protocol and
                         // transport layer for this service.
                         Log.d(TAG, "Unknown Service Type: " + service.getServiceType());
                     } else if (service.getServiceName().equals(serviceName)) {
                         // The name of the service tells the user what they'd be
                         // connecting to. It could be "Bob's Chat App".
                         Log.d(TAG, "Same machine: " + serviceName);
                     } else if (service.getServiceName().contains("NsdChat")){
                        // nsdManager.resolveService(service, resolveListener);
                 public void onServiceLost(NsdServiceInfo service) {
                     // When the network service is no longer available.
                     // Internal bookkeeping code goes here.
                     Log.e(TAG, "service lost: " + service);
                 public void onDiscoveryStopped(String serviceType) {
                     Log.i(TAG, "Discovery stopped: " + serviceType);
                 public void onStartDiscoveryFailed(String serviceType, int errorCode) {
                     Log.e(TAG, "Discovery failed: Error code:" + errorCode);
                 public void onStopDiscoveryFailed(String serviceType, int errorCode) {
                     Log.e(TAG, "Discovery failed: Error code:" + errorCode);
     public  void discover(Context c){
         nsdManager = (NsdManager)c.getSystemService(Context.NSD_SERVICE);
         nsdManager.discoverServices("_http._tcp.", NsdManager.PROTOCOL_DNS_SD, discoveryListener);
         //nsdManager = (NsdManager)c.getSystemService(Context.NSD_SERVICE);
     public  void discoverDevices(Context context)throws IOException {
         String re="Abdelhamid";
     public void print(String teta)

    *But I got the problem below: I thins it's an error complation, F art : art/runtime/java_vm_ext.cc:410] JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() F art : art/runtime/java_vm_ext.cc:410] at void android.os.Handler.(android.os.Handler$Callback, boolean) (Handler.java:200) F art : art/runtime/java_vm_ext.cc:410] at void android.os.Handler.() (Handler.java:114) F art : art/runtime/java_vm_ext.cc:410] at void android.app.Activity.() (Activity.java:865) F art : art/runtime/java_vm_ext.cc:410] at void org.qtproject.qt5.android.bindings.QtActivity.() (QtActivity.java:94)


Log in to reply