使用JNA User32平台图的NoSuchMethodError [英] NoSuchMethodError using JNA User32 platform map

查看:425
本文介绍了使用JNA User32平台图的NoSuchMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在第一次尝试使用User32.Instance时收到以下错误:

I received the following error on the first attempt of using the User32.Instance:

线程"main"中的异常java.lang.NoSuchMethodError:com.sun.jna.Native.load(Ljava/lang/String; Ljava/lang/Class; Ljava/util/Map;)Lcom/sun/jna/图书馆;
com.sun.jna.platform.win32.User32.(User32.java:48)

Exception in thread "main" java.lang.NoSuchMethodError: com.sun.jna.Native.load(Ljava/lang/String;Ljava/lang/Class;Ljava/util/Map;)Lcom/sun/jna/Library;
at com.sun.jna.platform.win32.User32.(User32.java:48)

尝试运行Windows User32类函数的JNA预定义映射.

whilst trying to run a JNA pre-defined mapping of the Windows User32 class functions.

我尝试运行以下代码:

HWND hwnd = User32.INSTANCE.FindWindow(null,"new 2 - Notepad++");
User32.INSTANCE.SetForegroundWindow(hwnd);

我必须声明自己的接口还是可以使用jna平台中的User32 JNA映射?我在做什么错了?

Do I have to declare my own Interface or am I able to use the User32 JNA mapping located in jna-platform? What am i doing wrong?

com.sun.jna.platform.win32.user32的该行中的错误:

The error is on this line from the com.sun.jna.platform.win32.user32:

User32 INSTANCE = Native.load("user32", User32.class, W32APIOptions.DEFAULT_OPTIONS);

推荐答案

我能够通过对旧的jna软件包(低于5.0.0版)和新的jna-platform软件包(5.0版)进行编译来重现此错误. 0):

I was able to reproduce this bug by compiling against an old jna package (pre-5.0.0) and a new jna-platform package (5.0.0):

Exception in thread "main" java.lang.NoSuchMethodError: com.sun.jna.Native.load(Ljava/lang/String;Ljava/lang/Class;Ljava/util/Map;)Lcom/sun/jna/Library;
    at com.sun.jna.platform.win32.User32.<clinit>(User32.java:48)
    at sandboxjava.Main.main(Main.java:8)

问题是JNA在版本5.0.0中弃用了Native.loadLibrary方法,并引入了Native.load方法.较新的jna-platform软件包使用了new方法,但是由于jna软件包是较旧的版本,因此load方法根本不存在于软件包中.

The issue is that JNA deprecated the Native.loadLibrary method in version 5.0.0 and introduced the Native.load method. The newer jna-platform package uses the new method, but because the jna package is an older version, the load method simply does not exist in the package.

您应该将jna软件包升级到5.0.0(在撰写本文时为最新),或者将jna-platform降级到5.0.0之前的版本.

You should either upgrade the jna package to 5.0.0 (latest at the time of writing), or downgrade jna-platform to a pre-5.0.0 version.

这篇关于使用JNA User32平台图的NoSuchMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆