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. JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception java.lang.ClassNotFoundException: Didn't find class
Forum Updated to NodeBB v4.3 + New Features

JNI DETECTED ERROR IN APPLICATION: JNI GetMethodID called with pending exception java.lang.ClassNotFoundException: Didn't find class

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
2 Posts 2 Posters 1.2k 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.
  • E Offline
    E Offline
    ENSAO_CHEIKH
    wrote on 1 Jun 2021, 22:02 last edited by ENSAO_CHEIKH 6 Jan 2021, 22:10
    #1

    0

    Please I want to build an NSD ( network services discovery) app, using Jni with Qt, But I get the following error: JNI DETECTED ERROR IN APPLICATION: JNI GetStaticMethodID called with pending exception java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference

    I am trying to call the function: discover()

    Here is the code below:

    import android.content.Context;
    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 static NsdManager.DiscoveryListener  discoveryListener;
          private static NsdManager nsdManager;
    
          private static Context context;
    
    
         public void initializeDiscoveryListener() {
    
             // Instantiate a new DiscoveryListener
    
               discoveryListener = new NsdManager.DiscoveryListener() {
    
                 // Called as soon as service discovery begins.
                 @Override
                 public void onDiscoveryStarted(String regType) {
                     Log.d(TAG, "Service discovery started");
                 }
    
                 @Override
                 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);
                     }
                 }
    
                 @Override
                 public void onServiceLost(NsdServiceInfo service) {
                     // When the network service is no longer available.
                     // Internal bookkeeping code goes here.
                     Log.e(TAG, "service lost: " + service);
                 }
    
                 @Override
                 public void onDiscoveryStopped(String serviceType) {
                     Log.i(TAG, "Discovery stopped: " + serviceType);
                 }
    
                 @Override
                 public void onStartDiscoveryFailed(String serviceType, int errorCode) {
                     Log.e(TAG, "Discovery failed: Error code:" + errorCode);
                     nsdManager.stopServiceDiscovery(this);
                 }
    
                 @Override
                 public void onStopDiscoveryFailed(String serviceType, int errorCode) {
                     Log.e(TAG, "Discovery failed: Error code:" + errorCode);
                     nsdManager.stopServiceDiscovery(this);
                 }
             };
         }
    
     public static void discover(){
         System.out.println("discoverServices");
         nsdManager = (NsdManager) context.getSystemService(Context.NSD_SERVICE);
         System.out.println("oui");
         nsdManager.discoverServices("_http._tcp.", NsdManager.PROTOCOL_DNS_SD, discoveryListener);
         System.out.println("oui");
    
     }
         //nsdManager = (NsdManager)c.getSystemService(Context.NSD_SERVICE);
    
     public static String discoverDevices(Context context)throws IOException {
    
         System.out.println("up");
         //MusicList scan= new MusicList();
         //System.out.println("up");
         discover();
         System.out.println("up");
         return "Abdelhamid";
         }
    
    
    
    
    
    
    
    }
    
    
    
    
    
    
    
    
    
    1 Reply Last reply
    0
    • S Offline
      S Offline
      sierdzio
      Moderators
      wrote on 2 Jun 2021, 08:20 last edited by
      #2

      Do you set the context anywhere? Doesn't look like it. The error tells you that it is null, you need to set the context before you call any methods from it.

      (Z(:^

      1 Reply Last reply
      0

      1/2

      1 Jun 2021, 22:02

      • Login

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