2014-01-13 42 views
0

我有一個小的JNI文件,它具有將char數組轉換爲字節數組的本地函數(因此我可以將它發送給我的C++客戶端)。找不到原生方法

的定義如下:

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

包名稱(其中庫加載是:

package com.example.communicationmoduleTCPIP 

而在類天然deffiniton是followd:

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


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

但是,當調用ConvertString函數時,我得到了以下錯誤:

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) 

難道問題是類(communicationmoduleTCPIP)是一個可運行的類嗎? I'T類中的運行,並具有以下定義(在服務器運行正常,當我評論的原生功能)

public class communicationmoduleTCPIP extends communicationmodule implements Runnable 

我有我想定義正確的看了看周圍的淨和閱讀一些後後,能對某些一個告訴我我做錯了什麼?歡迎任何建議。

回答

2

本地方法的名稱應與類全名:Java_com_example_communicationmoduleTCPIP_communicationmoduleTCPIP_ConvertString

+0

謝謝您的回答,我會檢查IK明天。回到你身邊。 (這是晚上) – Roy08

+0

謝謝你解決了我的問題! – Roy08