java系统。加载抛出NoSuchMethodError
我正在尝试使用JRE 1.7在windows上加载本机库。以下是我加载库的代码:
public boolean loadNativeLibrary(String libName){
try{
String libPath = RLibLocator.locateLibrary(libName);
File tmpLibPath = File.createTempFile("lib", ".dll");
InputStream libIn = PlatformGeneric.class.getClassLoader().getResourceAsStream(libPath);
byte[] decrypted = AES.decrypt(StreamUtils.readAll(libIn), RLibLocator.LIB_DATA_KEY);
FileOutputStream fout = new FileOutputStream(tmpLibPath);
fout.write(decrypted);
fout.flush();
libIn.close();
fout.close();
tmpLibPath.deleteOnExit();
System.load(tmpLibPath.getAbsolutePath());
return true;
}catch(Exception e){
Log.e("Platform/LibLoader", "Failed to load library: Exception: " + e.getClass().getName() + ": " + e.getMessage());
if(DEBUG)
e.printStackTrace();
}
return false;
}
如您所见,正在加载的库经过加密,然后在运行时解密,并使用System.load
加载。但是,当运行此代码时,应用程序抛出一个NoSuchMethodError
。堆栈跟踪如下所示:
Exception in thread "main" java.lang.NoSuchMethodError: <init>
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at PlatformGeneric.loadNativeLibrary(PlatformGeneric.java:225)
...
我已经检查了存储在临时文件夹中的解密库是否与未加密、初始编译的二进制文件相同(散列匹配)。我试图加载的库肯定没有错误,可以在这里找到源代码:https://github.com/kwhat/jnativehook
我做错什么了吗?如果是,我如何解决这个问题
注意: 我已经尝试过使用多个JRE(1.5-1.8)来运行它
共 (0) 个答案