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 8043709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:59:34+00:00 2026-06-05T04:59:34+00:00

Possible Duplicate: what is wrong with this call to the java method? The following

  • 0

Possible Duplicate:
what is wrong with this call to the java method?

The following C snippet calls a java function whenever the escape key is pressed. The first block of C snippet executes on a different thread and second block executes on a different thread.When i press the escape key,the message escape key pressed is displayed and then the jvm crashes.Why doesn’t the java function get called ?

C Code :

    if(called) {// starts on a different thread
    switch(param) {
        case VK_CONTROL:
            printf("Control pressed !\n");
            //(*Env)->CallVoidMethodA(Env,Obj,mid,"11");
            break;
        case VK_SHIFT:
            printf("Shift pressed !\n");
            //(*Env)->CallVoidMethodA(Env,Obj,mid,"10");
            break;
        case VK_ESCAPE:
            printf("Escape pressed !\n");
            JavaVM *jvm;
            JNIEnv *env;
            jmethodID mid;
            env = (*jvm)->AttachCurrentThread(jvm,&env,NULL);
            jclass cls = (*env)->GetObjectClass(env,Obj);
            mid = (*env)->GetMethodID(env,cls,"callBack","(Ljava/lang/String;)V");
            (*env)->CallVoidMethodA(env,Obj,mid,(*env)->NewStringUTF(env,"1B")); // Calling the java function
            break;
        default:
            printf("The default case\n");
            break;
    }}

    void Java_keylogger_TestKeys_initializeJNIVars
     (JNIEnv *env, jobject obj) { // starts on a different thread

      Obj = (*env)->NewGlobalRef(env,obj);
      if(Obj == NULL) {
        printf("Obj is Null\n");
      }
      called = TRUE;
   }

Java Snippet :

    public void callBack(String key) {
      String x = KeyEvent.getKeyText(Integer.parseInt(key, 16));
      System.out.println(x);
    }

I have uploaded the complete code with the output here.

  • 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-05T04:59:36+00:00Added an answer on June 5, 2026 at 4:59 am

    You need to initialize your jvm variable. You can do this using JNI_CreateJavaVM()method. See here for more information: http://docs.oracle.com/javase/1.4.2/docs/guide/jni/spec/invocation.html

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

Sidebar

Related Questions

Possible Duplicate: Call to a member function on a non-object What is wrong with
Possible Duplicate: Why is the 'this' keyword required to call an extension method from
Possible Duplicate: What's wrong with this division? If you divide 2 / 3 ,
Possible Duplicate: How to sort a Map<Key, Value> on the values in Java? Here's
Possible Duplicate: $(this) doesn't work in a function Im having a problem targeting the
Possible Duplicate: Javascript - array.contains(obj) What's wrong with this: var zipCodes =(['90001','90002','90003']); Test if
Possible Duplicate: onKeyDown() or onBackPressed() I don't know what is wrong, but whenever I
Possible Duplicate: When do you use the “this” keyword? If I have the following
Possible Duplicate: Yield In VB.NET In C#, when writing a function that returns an
Possible Duplicate: Finding the Variable Name passed to a Function in C# In C#,

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.