I received the following error on the first attempt of using the User32.Instance:
Exception in thread \"main\" java.lang.NoSuchMethodError: com.sun.jna.N
Update the maven using below dependency, It worked for me.
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.5.1</version>
</dependency>
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)
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.
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.