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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:54:54+00:00 2026-05-25T16:54:54+00:00

I have a JNI problem which I hope someone can help me out with.

  • 0

I have a JNI problem which I hope someone can help me out with.
I’m trying to call on a constructor of a Java class called LUSOutputJNI from a native thread.
It keeps failing on FindClass(…) of this specific class.

Here is the code:

 LOGE("1");
    JNIEnv *env = NULL;

    LOGE("2");
    int res = -1;
    res = g_vm->AttachCurrentThread(&env, NULL);

    if(env == NULL)
    {
        LOGE("env is NULL, AttachCurrentThread failed");;
    }


    if(res >= 0)
        LOGE("AttachCurrentThread was successful");
    jclass clazz = NULL;
    jmethodID cid;

    jclass clazzESEngine;
    jmethodID callbackid;

    jobject jCoreOut;
    static jfieldID fid_ActionState = NULL;
    static jfieldID fid_nSpeed = NULL;
    static jfieldID fid_nType = NULL;
    static jfieldID fid_nInProcess = NULL;
    static jfieldID fid_nX = NULL;
    static jfieldID fid_nY = NULL;
    LOGE("3");

    static const char* const ECOClassName = "lus/android/sdk/LUSOutputJNI";
    //static const char* const ECOClassName = "android/widget/TextView";
    clazz = env->FindClass(ECOClassName);
    if (clazz == NULL) {
        LOGE("Can't find class LUSOutputJNI");

    }
    else
        LOGE("lus/android/sdk/LUSOutputJNI was found, YEY!!");

    LOGE("4");
    cid = env->GetMethodID(clazz,"<init>", "()V");
    LOGE("5");
    jCoreOut = env->NewObject(clazz, cid);

    LOGE("6");    

Here is the logcat output from when it fails:

E/lusCore_JNI( 3040): 1
E/lusCore_JNI( 3040): 2
E/lusCore_JNI( 3040): AttachCurrentThread was successful
E/lusCore_JNI( 3040): 3
E/lusCore_JNI( 3040): Can't find class LUSOutputJNI
E/lusCore_JNI( 3040): 4
W/dalvikvm( 3040): JNI WARNING: JNI method called with exception raised  

Observations:

  • I get a result from AttachCurrentThread which is 0, which means that this attachment was successful + the env pointer is no longer NULL.
  • I’m sure about the package name declaration of LUSOutputJNI (triple checked it…)
  • When I try to run FindClass(..) with a more popular class name such as android/widget/TextView , I get a positive match. It is there. Meaning the thread attachment and the env variables are ok. (Can I assume that?)
  • When I try to run the following code from a JNI method which has a JNI thread running it, it finds the LUSOutputJNI class without a problem.

What am I doing wrong?

Help will be much appreciated 🙂

Thanks for your time,

Ita

  • 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-05-25T16:54:54+00:00Added an answer on May 25, 2026 at 4:54 pm

    Found the answer \ work around in here. (Look for FAQ: “FindClass didn’t find my class” in
    JNI tips)

    I basicaly saved a global ref to the needed jclass objects.
    Did however had to overcome some evil JNI changes between C/JNI and C++/JNI in order for the code to compile.
    This is how I got the NewGlobalRef to compile and work.

    jclass localRefCls = env->FindClass(strLUSClassName);
    if (localRefCls == NULL) {
        LOGE("Can't find class %s",strLUSCoreClassName);
        return result;
    }
    
    //cache the EyeSightCore ref as global
     /* Create a global reference */
     clazzLUSCore = (_jclass*)env->NewGlobalRef(localRefCls);
    
     /* The local reference is no longer useful */
     env->DeleteLocalRef(localRefCls);
    
     /* Is the global reference created successfully? */
     if (clazzLUSCore == NULL) {
         LOGE("Error - clazzLUSCore is still null when it is suppose to be global");
         return result; /* out of memory exception thrown */
     }  
    

    I hope this helps anyone.

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

Sidebar

Related Questions

I have a JNI method to access java method which returns an Integer object.
We have system here that uses Java JNI to call a function in a
I have an android application which uses jni and I'm trying to automate build
I have a problem sharing a stream between Java and C with JNI. I
I have a Java function which can take variable number of parameters and in
I have a Java application which interacts with native code using JNI. The native
I am just starting out with JNI and I have a following problem. I
I have an Java applet that loads native code through JNI. Everything worked just
I have a C program that stores some object in java store using JNI.
I am new to JNI. And have a few questions : Can JNI handle

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.