jni String to *char and java.lang.UnsatisfiedLinkError:
jni String to *char and java.lang.UnsatisfiedLinkError:
im 尝试使用 JNI 运行简单的程序,在我尝试使用字符串之前一切都运行良好:
您好.java:
public class hello {
public native String getLine(String name) ;
public static void main (String args[]) {
String str = "Pawel" ;
hello h = new hello () ;
System.out.println(h.getLine(str)) ;
}
static {
System.loadLibrary ( "hello" ) ;
}
}
你好:
#include<stdio.h>
#include<jni.h>
#include "hello.h"
JNIEXPORT jstring JNICALL
Java_Prompt_getLine(JNIEnv *env, jobject obj, jstring prompt)
{
char buf[128];
const jbyte *str;
str = (*env)->GetStringUTFChars(env, prompt, NULL);
if (str == NULL) {
return NULL;
}
printf("%s", str);
(*env)->ReleaseStringUTFChars(env, prompt, str);
scanf("%s", buf);
return (*env)->NewStringUTF(env, buf);
}
你好:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class hello */
#ifndef _Included_hello
#define _Included_hello
#ifdef __cplusplus
extern "C" {
#endif
JNIEXPORT jstring JNICALL Java_hello_getLine
(JNIEnv *, jobject, jstring);
#ifdef __cplusplus
}
#endif
#endif
IM 编译:
gcc -fPIC -I /usr/lib/jvm/java-7-openjdk-amd64/include -I /usr/lib/jvm/java-7-openjdk-amd64/include/linux -shared -o libhello.so hello.c
并运行:
java -Djava.library.path=. hello
输出:
Exception in thread "main" java.lang.UnsatisfiedLinkError: hello.getLine(Ljava/lang/String;)Ljava/lang/String;
at hello.getLine(Native Method)
at hello.main(hello.java:9) //it points to native function call
怎么了?
将
Java_Prompt_getLine
函数重命名为Java_hello_getLine
in hello.c
相关文章:
- java.lang.IndexOutOfBoundsException with JNA
- Android Studio 3.1.2 - 无法运行C++子例程"No implementation found for Java.lang.String..."
- java.lang.UnsatisfiedLinkError: Abc.greetings()V
- java.lang.Field 等效于 c++ 中
- 为什么日食总是发生错误"An internal error occurred during: "通知选择侦听器". java.lang.StackOverflowError"
- java.lang.UnsatisfiedLinkError:未找到实现
- JNI GetMethodID 调用,带有挂起的异常 java.lang.ClassNotFoundException
- java.lang.UnsatisfiedLinkError: dlopen failed: 无法加载"libPrivateSsl.so"所需的库"libcrypto.so.1.0.0";
- 单元测试环境中的"java.lang.UnsatisfiedLinkError: *.so: Can't find dependent libraries"
- JNI 代码返回字符串,但得到错误 java.lang.UnsatisfiedLinkError: com.packag
- 如何在没有System32的情况下解决"java.lang.UnsatisfiedLinkError:找不到依
- JNA从DLL调用C++对象-java.lang.IollegalArgumentException:Structure
- 线程中的异常 "main" java.lang.UnsatisfiedLinkError: no JNTIest in java.library.path
- jni java.lang.unsatisfiedlinkerror,无法链接方法
- 从WordCount Hadoop示例调用Helloworld Jni函数,给出错误Java.lang.unsatisf
- 在hadoop 2.7.4的自定义排序类中调用C函数,给出Java.lang.unsatisfiedlinkerror
- 在运行时获得Java.lang.unsatisfiedlinkerror
- AndroidRuntime: java.lang.UnsatisfiedLinkError: Native metho
- 线程"main" java.lang.UnsatisfiedLinkError: Native.initiate(I)V 从 Java 运行本机 dll 时
- JNI : 线程"AWT-EventQueue-0" java.lang.UnsatisfiedLinkError 中的异常