[英]JNI UnsatisfiedLink Error
So I'm new to JNI and I'm following a simple hello word example but I keep getting error UnsatisfiedLinkError
. 所以我是JNI的新手,我正在关注一个简单的hello单词示例,但我不断收到错误
UnsatisfiedLinkError
。 What am I doing wrong? 我究竟做错了什么? Here's my .h file:
这是我的.h文件:
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class JNITEST_jnihellonative */
#ifndef _Included_JNITEST_jnihellonative
#define _Included_JNITEST_jnihellonative
#ifdef __cplusplus
extern "C" {
#endif
/*
* Class: JNITEST_jnihellonative
* Method: hellofromc
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_JNITEST_jnihellonative_hellofromc(JNIEnv *,jobject);
#ifdef __cplusplus
}
#endif
#endif
.c File .c文件
#include <jni.h>
#include<stdio.h>
#include<windows.h>
#include "jnihellonative.h"
JNIEXPORT void JNICALL
Java_JNITESTS_jnihellonative_hellofromc(JNIEnv *env, jobject obj){
printf("Hello World");
return;
}
java main class java主类
package JNITEST;
public class Jnihello {
public static void main(String[] args) {
jnihellonative jniprint = new jnihellonative();
jniprint.hellofromc();
}
}
java class java类
package JNITEST;
public class jnihellonative {
public native void hellofromc();
static{
System.load("C:\\Users\\Kevin\\Documents\\NetBeansProjects\\JniHelloTest.dll");
}
}
I keep getting this error 我一直收到这个错误
Exception in thread "main" java.lang.UnsatisfiedLinkError: JNITEST.jnihellonative.hellofromc()V
at JNITEST.jnihellonative.hellofromc(Native Method)
at JNITEST.Jnihello.main(Jnihello.java:19)
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)
I have tried using System.load() and System.loadLibrary() but i get same error. 我已经尝试使用System.load()和System.loadLibrary()但我得到相同的错误。
You've changed the name of your class since you generated the .h file and wrote the .c file. 自生成.h文件并编写.c文件以来,您已更改了类的名称。 The .h file has
jnihellonative
, your Java code has Jnihello
. .h文件有
jnihellonative
,你的Java代码有Jnihello
。
I have tried using System.load() and System.loadLibrary()
我尝试过使用System.load()和System.loadLibrary()
Irrelevant. 无关紧要。 You're not getting the exception from either of these, you're getting it when calling your native method.
你没有从这两个中获得异常,你在调用本机方法时得到它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.