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

  • Home
  • SEARCH
  • 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 8323797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T23:49:58+00:00 2026-06-08T23:49:58+00:00

My application makes calls to a native library, and then within the native library,

  • 0

My application makes calls to a native library, and then within the native library, makes calls back to the Java code. I have the calls TO the native library working correctly ( I’m pretty sure ), but not its telling me that it can’t find the Java functions when trying to call them from the C file.

The application doesn’t even crash, there is no pop up telling me it closed unexpectedly, it just flashes a black screen and nothing happens.

The code I am trying to reproduce was originally made in C for Palm Pilot, and is being transferred to an Android device. This is the original call in C I am trying to duplicate…

InitRelay(Changeit,getit,putit,flushit,delayit);

The parameters in the call above are function names, the functions are here below:

void Changeit(WORD baud){
    ChangeRate(baud);
}

extern Boolean ChangeRate(UInt32 baud)
{...}

Int16 getit(UInt16 t) {...}

void putit( BYTE p ) {...}

void flushit(void){...}

extern void delayit( UInt16 wait ) {...}

This is InitRelay shown in my .c file:

BYTE __stdcall InitRelay(fp_setbaud _setbaud, fp_get _get, fp_put _put, fp_flush _flush, fp_delay _delay){

    RelayAPI_SetBaud=_setbaud;
    RelayAPI_get=_get;
    RelayAPI_put=_put;
    RelayAPI_flush=_flush;
    RelayAPI_delay=_delay;
    ....
}

The parameters shown in above are typedefed in my .h file:

typedef void (__stdcall *fp_setbaud)(WORD);
typedef short (__stdcall *fp_get)(WORD);
typedef void (__stdcall *fp_put)(BYTE);
typedef void (__stdcall *fp_flush)(void);
typedef void (__stdcall *fp_delay)(WORD);

The WORD/BYTE/DWORD types are defined in a separate .h file shown here:

typedef unsigned char BYTE;
typedef unsigned short WORD;
typedef unsigned long DWORD;

Now, in my Android code, I call a function I made called InitRelayJava(), all of my data for the application is stored in a separate class called RelayAPIModel. I created a nested class within that to store all of my native functions. I did this so that I can access these functions the same way no matter what Activity the application is currently in.

public class RelayAPIModel {
    ....
    public static class NativeCalls {
        static {
            System.loadLibrary( "RelayAPI" );
        }

        public native static byte InitRelayJava();

    public native static void FreeRelayJava();


        public static void changeItJavaWrapper( short l ) {
            mModelService.changeitJava( l );
        }

        public static void flushItJavaWrapper() {
            mModelService.flushitJava();
        }

        public static void putItJavaWrapper( byte[] p ) {
            mModelService.putitJava( p );
        }

        public static void delayItJavaWrapper( short wait ) {
            mModelService.delayitJava( wait );
        }

        public static short getItJavaWrapper( short s ) {           
            return mModelService.getitJava( s );
        }
    }
 }

The calls made inside the *Wrapper functions go to a separate class that I have to handle all of the applications bluetooth capabilities. I do not think that those are needed for this problem.

This is what InitRelayJava looks like in my C code…

BYTE Java_my_eti_commander_RelayAPIModel_00024NativeCalls_InitRelayJava( JNIEnv *env, jobject obj  ) {

    myEnv = (env);
    bluetoothClass = (*env)->GetObjectClass( env, obj );
    myObject = obj;

    changeID = (*myEnv)->GetMethodID( myEnv, myObject, "changeitJavaWrapper", "(S)V"  );
    getID    = (*myEnv)->GetMethodID( myEnv, myObject, "getitJavaWrapper"   , "(S)S"   );
    putID    = (*myEnv)->GetMethodID( myEnv, myObject, "putitJavaWrapper"   , "(B)V" );
    flushID  = (*myEnv)->GetMethodID( myEnv, myObject, "flushitJavaWrapper" , "()V"   );
    delayID  = (*myEnv)->GetMethodID( myEnv, myObject, "delayitJavaWrapper" , "(S)V"  );
...
}

This is the LogCat I am receiving…

08-02 10:27:32.406: D/dalvikvm(28376): Trying to load lib /data/data/my.eti.commander/lib/libRelayAPI.so 0x40515430
08-02 10:27:32.406: D/dalvikvm(28376): Added shared lib /data/data/my.eti.commander/lib/libRelayAPI.so 0x40515430
08-02 10:27:32.406: D/dalvikvm(28376): No JNI_OnLoad found in /data/data/my.eti.commander/lib/libRelayAPI.so 0x40515430, skipping init
08-02 10:27:32.406: D/dalvikvm(28376): GetMethodID: method not found: Lmy/eti/commander/RelayAPIModel$NativeCalls;.changeitJavaWrapper:(S)V
08-02 10:27:32.413: D/dalvikvm(28376): GetMethodID: method not found: Lmy/eti/commander/RelayAPIModel$NativeCalls;.getitJavaWrapper:(S)S
08-02 10:27:32.413: E/dalvikvm(28376): Class lookup Ljava/lang/NoSuchMethodError; attempted while exception Ljava/lang/NoSuchMethodError; pending
  • 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-08T23:49:59+00:00Added an answer on June 8, 2026 at 11:49 pm

    InitRelayJava is a static method – that means your second parameter (obj) is a class object pointer, not a this pointer. So get rid of the following line:

    bluetoothClass = (*env)->GetObjectClass( env, obj );
    

    and instead pass obj to GetMethodID(), like this:

    changeID = (*myEnv)->GetMethodID( myEnv, obj, "changeitJavaWrapper", "(I)Z"  ); 
    

    EDIT: also, your parameter/return type signatures are wrong. Short is not the same as int, so the signature for changeitJavaWrapper is “(S)Z”, for getitJavaWrapper is “()I” as it takes no parameters and returns an int. Be more careful please; it does not take an advanced knowledge of C to get those right, just some self-checking. This project of yours is inching into What have you tried? territory.

    Cheat sheet on JNI type codes here.

    Let me try and anticipate your next question – you cannot call those methods. Of course you cannot, it’s not possible to call a nonstatic method from a static one. Your Java callbacks are all nonstatic, while the native method is static. Either make them static, or make the native method nonstatic and insert the GetObjectClass back.

    EDIT2: so you changed your Java methods to static without telling. Now instead of (*env)->GetMethodID() you need to call (*env)->GetStaticMethodID() to get the method ID. Same parameters.

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

Sidebar

Related Questions

I have a Java application that calls lots of different native methods of a
I have a .NET application that makes calls to a native Win32 DLL using
I am looking at an asp.net application that makes calls to a database within
So we have an application that makes udp calls and sends packets. However, since
I'm working on a multi-threaded C# Windows application that makes frequent calls into a
I'm in the process of doing some Java<->.NET interop code using a native library
I'm writing an application (on android) that uses both java code, and native code.
I have a Windows Forms application which makes calls to web services via proxies
I have a Linux C++ application that creates a JVM and makes JNI calls.
My application makes several calls to an Action method (ASP .NET MVC) which returns

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.