0

I have a small JNI file with a native function that converts a char array to a byte array (So i can send it to my C++ client).

The definition is as followed:

JNIEXPORT jbyteArray JNICALL Java_com_example_comtesttcp_communicationmoduleTCPIP_ConvertString(
        JNIEnv * env, jobject,
        jcharArray Buffer)

The package name (where the library is loaded is:

package com.example.communicationmoduleTCPIP

And the native deffiniton in the class is as followd:

// Load helper functions library
static {
   System.loadLibrary("HelperFunctions");
}


  public native byte[] ConvertString(char[] Buffer);

But when the ConvertString function is called then i get the folowing error:

01-13 21:07:21.890: W/dalvikvm(22611): No implementation found for native Lcom/example/communicationmoduleTCPIP/communicationmoduleTCPIP;.ConvertString:([C)[B
01-13 21:07:21.890: W/dalvikvm(22611): threadid=11: thread exiting with uncaught exception (group=0x412b52a0)
01-13 21:07:21.900: E/AndroidRuntime(22611): FATAL EXCEPTION: Thread-821
01-13 21:07:21.900: E/AndroidRuntime(22611): java.lang.UnsatisfiedLinkError: Native method not found: com.example.communicationmoduleTCPIP.communicationmoduleTCPIP.ConvertString:([C)[B
01-13 21:07:21.900: E/AndroidRuntime(22611):    at com.example.communicationmoduleTCPIP.communicationmoduleTCPIP.ConvertString(Native Method)
01-13 21:07:21.900: E/AndroidRuntime(22611):    at com.example.communicationmoduleTCPIP.communicationmoduleTCPIP.SendBuffer(communicationmoduleTCPIP.java:164)
01-13 21:07:21.900: E/AndroidRuntime(22611):    at com.example.communicationmoduleTCPIP.communicationmoduleTCPIP.RunServer(communicationmoduleTCPIP.java:107)
01-13 21:07:21.900: E/AndroidRuntime(22611):    at com.example.communicationmoduleTCPIP.communicationmoduleTCPIP.run(communicationmoduleTCPIP.java:368)
01-13 21:07:21.900: E/AndroidRuntime(22611):    at java.lang.Thread.run(Thread.java:856)

Could the problem be that the class (communicationmoduleTCPIP) is a runnable class? I't runs in a class and has the following definition (the server runs fine when i comment the native function)

public class communicationmoduleTCPIP extends communicationmodule implements Runnable

I have looked around on the net and after reading some post i think definition right, can some one tell me what i'm doing wrong? Any suggestions are welcome.

janos
  • 120,954
  • 29
  • 226
  • 236
Roy08
  • 253
  • 2
  • 7
  • 21

1 Answers1

2

the native method name should match the class full name: Java_com_example_communicationmoduleTCPIP_communicationmoduleTCPIP_ConvertString

Yazan Jaber
  • 2,068
  • 25
  • 36
  • Thank you for your answer, i will check ik tomorrow. And get back to you. (It is night here) – Roy08 Jan 13 '14 at 20:43