NoSuchMethodError using JNA User32 platform map

后端 未结 2 760
太阳男子
太阳男子 2021-01-23 05:36

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

相关标签:
2条回答
  • 2021-01-23 05:47

    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>
    
    0 讨论(0)
  • 2021-01-23 05:53

    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.

    0 讨论(0)
提交回复
热议问题