未找到本机方法 [英] Native method not found

查看:148
本文介绍了未找到本机方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的JNI文件,具有将char数组转换为字节数组的本地函数(所以我可以将其发送到我的C ++客户端)。

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).

定义如下:

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);

但是当ConvertString函数被调用时,我会得到以下错误:

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)

可能的问题是类(communicationmoduleTCPIP)是一个可运行的类?我没有运行在一个类中,并具有以下定义(当我评论本机功能时,服务器运行正常)

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.

推荐答案

本机方法名称应与类全名匹配: Java_com_example_communicationmoduleTCPIP_communicationmoduleTCPIP_ConvertString

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

这篇关于未找到本机方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆