NoSuchFieldError: SIZE

624 views
Skip to first unread message

Rick Ley

unread,
Oct 23, 2018, 8:19:13 PM10/23/18
to Java Native Access
I'm new to using JNA. I have the following code

WinNT.HANDLE handle = Advapi32.INSTANCE.RegisterEventSource(null, "JavaTest");
String[] eventText = {"Test String"};
Advapi32.INSTANCE.ReportEvent(handle, 4, 0, 123, null, 1, 0, eventText, null);

which is throwing the following exceptions on the call to RegisterEventSource: 
Exception in thread "main" java.lang.NoSuchFieldError: SIZE
 at com.sun.jna.platform.win32.WinBase.<clinit>(WinBase.java:52)
 at com.sun.jna.platform.win32.WinNT$HANDLE.fromNative(WinNT.java:1366)
 at com.sun.jna.NativeMappedConverter.fromNative(NativeMappedConverter.java:78)
 at com.sun.jna.Function.invoke(Function.java:369)
 at com.sun.jna.Library$Handler.invoke(Library.java:244)
 at com.sun.proxy.$Proxy0.RegisterEventSource(Unknown Source)
 at Main.main(Main.java:81)

I have tested that I am able to load the Advapi32 library directly by calling System.loadLibrary, so I don't think that is the issue. From looking at the tests on the GitHub repo, it looks like I am using it similarly. The line the exception comes from is initializing an int to a constant value, so I'm not sure where SIZE is coming from. 

Any insight or direction on how to continue debugging would be greatly appreciated. Thank you!

Matthias Bläsing

unread,
Oct 24, 2018, 3:33:29 AM10/24/18
to jna-...@googlegroups.com
Hey Rick,

Am Dienstag, den 23.10.2018, 17:19 -0700 schrieb Rick Ley:
> WinNT.HANDLE handle = Advapi32.INSTANCE.RegisterEventSource(null, "JavaTest");
> String[] eventText = {"Test String"};
> Advapi32.INSTANCE.ReportEvent(handle, 4, 0, 123, null, 1, 0, eventText, null);
>
> which is throwing the following exceptions on the call to RegisterEventSource:
> Exception in thread "main" java.lang.NoSuchFieldError: SIZE
> at com.sun.jna.platform.win32.WinBase.<clinit>(WinBase.java:52)
> at com.sun.jna.platform.win32.WinNT$HANDLE.fromNative(WinNT.java:1366)
> at com.sun.jna.NativeMappedConverter.fromNative(NativeMappedConverter.java:78)
> at com.sun.jna.Function.invoke(Function.java:369)
> at com.sun.jna.Library$Handler.invoke(Library.java:244)
> at com.sun.proxy.$Proxy0.RegisterEventSource(Unknown Source)
> at Main.main(Main.java:81)
>
> I have tested that I am able to load the Advapi32 library directly by
> calling System.loadLibrary, so I don't think that is the issue. From
> looking at the tests on the GitHub repo, it looks like I am using it
> similarly. The line the exception comes from is initializing an int
> to a constant value, so I'm not sure where SIZE is coming from.

you are mixing Versions. The field Pointer#SIZE was removed in the
transition from 4.5.2 to 5.0.0. The error you are seeing can be
explained, if jna 4.5.X and jna-platform 5.0.0 are used together.

So I suggest you check your dependencies.

Matthias

Rick Ley

unread,
Oct 24, 2018, 2:51:07 PM10/24/18
to Java Native Access
For some reason I didn't see that 5.0.0 was available. That fixed the bug. Thank you!
Reply all
Reply to author
Forward
0 new messages