【问题标题】:Native method not found未找到本机方法
【发布时间】:2014-01-13 20:17:06
【问题描述】:

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

定义如下:

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

包名(加载库的地方是:

package com.example.communicationmoduleTCPIP

类中的原生定义如下:

// 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)是一个可运行的类吗?我不在一个类中运行并且具有以下定义(当我评论本机函数时服务器运行良好)

public class communicationmoduleTCPIP extends communicationmodule implements Runnable

我在网上环顾四周,在阅读了一些帖子后,我认为定义是正确的,有人能告诉我我做错了什么吗?欢迎提出任何建议。

【问题讨论】:

    标签: java android eclipse multithreading java-native-interface


    【解决方案1】:

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

    【讨论】:

    • 感谢您的回答,我明天会检查 ik。并回复你。 (这里是晚上)
    猜你喜欢
    • 2014-03-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多