Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:11:51+00:00 2026-06-12T08:11:51+00:00

I try to get jMethodID of the method in the java code ,but when

  • 0

I try to get jMethodID of the method in the java code ,but when I call this particular function, that does that an exception is thrown :

Exception in thread "AWT-EventQueue-0" java.lang.NoSuchMethodError: displayKeyStrokes
at org.suhail.keylogger.HelperClasses.NativeMethods.initializeJNIVars(Native Method)
at org.suhail.keylogger.GUI.MainGUI.jMenuItem1ActionPerformed(MainGUI.java:356)
.
.
.

I do not understand the reason for this. Following is the C code snippet that gets called from the java method :

void Java_org_suhail_keylogger_HelperClasses_NativeMethods_initializeJNIVars
(JNIEnv *env, jobject obj) {
 jclass cls = (*env)->GetObjectClass(env,obj);
 callBackToDeliverKeyStroke = (*env)->GetMethodID(env,cls,"displayKeyStrokes","()V");
 object = (*env)->NewGlobalRef(env,obj);
 if(object == NULL | callBackToDeliverKeyStroke == NULL | cls == NULL) {
    printf("Initialization error...One of the variable is Null\n");
 }
}

And this is the method named displayKeyStrokes in the java code :

 public void displayKeyStrokes() {
    System.out.println("Java Message : A Key has been pressed");
}

What could be the reason I am getting an exception ?

EDIT :

Java Code that calls JNI Code :

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
    jMenuItem1.setEnabled(false);
    jMenuItem2.setEnabled(true);
    try {
       System.loadLibrary("Dll_PKeylogger"); // Load the dll written to listen to the tapping of keys
       nativeMethods.initializeJNIVars(); // CALL
    }catch(Exception exc) {
        exc.printStackTrace();
    }
}

NativeMethods Class (declares the native methods)

package org.suhail.keylogger.HelperClasses;

public class NativeMethods {

 public native void initializeJNIVars();
 public native void unregisterHook(); 

}

NOTE : I am calling the method initializeJNIVars on the object of another class named NativeMethods and the method jMenuItem1ActionPerformed is called from an anonymous inner class whenever an event occurs as :

        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            jMenuItem1ActionPerformed(evt);
        }
    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:11:52+00:00Added an answer on June 12, 2026 at 8:11 am

    You state:

    jMenuItem1ActionPerformed is called from an anonymous class which is inside the same class as displayKeyStrokes. And yes jMenuItem1ActionPerformed is in the same class as jMenuItem1ActionPerformed except it is called from anonymous inner class as shown here

    That’s likely your problem then. The jMenuItem1ActionPerformed being in an anonymous inner class is important and means that it is in a different class from jMenuItem1ActionPerformed, and that this will need to be taken into account when you try to get the method ID from your JNI C code.

    Consider giving your initializeJNIVars() method a parameter that takes an instance of the outer class, and then pass that instance into the parameter and use it when you call GetMethodID(...). Note that you will have to pass the parameter in as OuterClassName.this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a problem : I try to call a java method that's supposed
I try to get this following url using the downloadURL function as follows: http://www.ncbi.nlm.nih.gov/nuccore/27884304
I try get xml file with this code: HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response
I have a function in Jquery, that try get html from an page: $.ajax({
i try to get my FragmentPagerAdapter working, but the examples are a bit to
I try to get the main window handle using following code in Lazarus (Free
i try get curent coordinate and addres with NETWORK_PROVIDER in trhead, but when i
I am facing problem in android-ndk. When i try to call a java nan-static
When I execute the following code, I get an exception. I think it is
I write a java program that has a json parser to get some data.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.