我找到了这个库,我非常喜欢它......但我无法开始使用它......我不知道我做错了什么,但谁能帮助我?
我已经阅读了 wiki 和环境设置。我正在尝试用 Java 调用 C# 来做一个简单的 hello world。
但我收到此错误:
java.lang.UnsatisfiedLinkError: net.sf.jni4net.Bridge.initDotNet()I
这是我在 Eclipse 中的文件夹设置:https ://cloud.githubusercontent.com/assets/6147142/8265327/e2419670-16cd-11e5-85bd-dae9ea275186.png
这是我的主要课程:
package testJni4net;
import java.io.IOException;
import java.lang.String;
import net.sf.jni4net.Bridge;
import system.*;
import system.Object;
import system.io.TextWriter;
import system.collections.IDictionary;
import system.collections.IEnumerator;
public class Teste1 {
public static void main(String[] args) throws IOException {
// create bridge, with default setup
// it will lookup jni4net.n.dll next to jni4net.j.jar
Bridge.setVerbose(true);
Bridge.init();
// here you go!
Console.WriteLine("Hello .NET world!\n");
// OK, simple hello is boring, let's play with System.Environment
// they are Hashtable realy
final IDictionary variables = system.Environment
.GetEnvironmentVariables();
// let's enumerate all keys
final IEnumerator keys = variables.getKeys().GetEnumerator();
while (keys.MoveNext()) {
// there hash table is not generic and returns system.Object
// but we know is should be system.String, so we could cast
final system.String key = (system.String) keys.getCurrent();
Console.Write(key);
// this is automatic conversion of JVM string to system.String
Console.Write(" : ");
// we use the hashtable
Object value = variables.getItem(key);
// and this is JVM toString() redirected to CLR ToString() method
String valueToString = value.toString();
Console.WriteLine(valueToString);
}
// Console output is really TextWriter on stream
final TextWriter writer = Console.getOut();
writer.Flush();
}
}
这是完整的堆栈跟踪:
Can't initialize jni4net Bridgenet.sf.jni4net.Bridge.initDotNet()I
Exception in thread "main" net.sf.jni4net.inj.INJException: Can't initialize jni4net Bridge
at net.sf.jni4net.CLRLoader.init(CLRLoader.java:45)
at net.sf.jni4net.Bridge.init(Bridge.java:35)
at net.sf.jni4net.Bridge.init(Bridge.java:31)
at testJni4net.Teste1.main(Teste1.java:19)
Caused by: java.lang.UnsatisfiedLinkError: net.sf.jni4net.Bridge.initDotNet()I
at net.sf.jni4net.Bridge.initDotNet(Native Method)
at net.sf.jni4net.CLRLoader.init(CLRLoader.java:37)
... 3 more