1

I tried to reproduce the attempt to make a capture of a window following : Java - Window Image (2 years old post)

I'm using JNA 3.5.0 and tested the unmodified code under XP and 7 with jre 7, and both failed with the same trace :

    Exception in thread "main" java.lang.AbstractMethodError:
    com.sun.jna.Structure.getFieldOrder()Ljava/util/List;
    at com.sun.jna.Structure.fieldOrder(Structure.java:831)
at com.sun.jna.Structure.getFields(Structure.java:857)
at com.sun.jna.Structure.deriveLayout(Structure.java:983)
at com.sun.jna.Structure.calculateSize(Structure.java:908)
at com.sun.jna.Structure.calculateSize(Structure.java:896)
at com.sun.jna.Structure.allocateMemory(Structure.java:357)
at com.sun.jna.Structure.<init>(Structure.java:191)
at com.sun.jna.Structure.<init>(Structure.java:180)
at com.sun.jna.Structure.<init>(Structure.java:167)
at com.sun.jna.Structure.<init>(Structure.java:159)
at com.sun.jna.platform.win32.WinDef$RECT.<init>(WinDef.java:320)
at Paint.capture(Paint.java:24)
at Paint.<init>(Paint.java:71)
at Paint.main(Paint.java:64)

To reproduce it simply just run :

import com.sun.jna.platform.win32.WinDef.RECT;

public class Test {
    public static void main(String[] args) {
    RECT rect = new RECT();
    }
}

If I understand JNA correctly, com.sun.jna.platform.win32.WinDef should be mapped to a system DLL by default.

It seems that the mapping is not correctly done.

I tried to figure out how to map WinDef to needed dll but couldn't find out how to do this with com.sun.jna.Native.loadLibrary method.

I don't understand why a AbstractMethodError is thrown instead of an UnsatisfiedLinkError, so I'm not sure the library loading is really the problem.

Instanciating com.sun.jna.Structure causes the exception, bug I didn't find any information on wether it could be fixed by a native library loading or it is a bug that has another cause.

I thought it could be Windows rights (admin) that my application doesn't acquire.

Or maybe I have to explicitely precise some pathes to jna so that he can find the dlls (but as I said before, it is no UnsatisfiedLinkError so it shouldn't be that).

If you have any experience with JNA and can give me some advice, please answer me.

Given the stacktrace, the understanding of JNA libraries I acquired so far, hours of searches and javadoc exploring, I obviously missed something that a JNA average user could probably find it (the original post is qualified of "Working example").

By the way, if you have any links or resources about jna (didn't find many), please post them :)

Thanks in advance !

Community
  • 1
  • 1
Pierre Mardon
  • 727
  • 8
  • 25
  • Can you tell us more about exactly what you're trying to do and the code you're using to try to do this? Are you simply copying the code and trying to use it as is? Have you instead tried to use smaller bits of the code to see what it does and to test it in isolation? – Hovercraft Full Of Eels Oct 27 '12 at 02:55
  • I both tried to use the original code and manipulated it to understand what was going on. Excuse me but I had to precise that I'm using the checked answer code in the other post. And I can't figure out why there's a problem instanciating this Structure class. – Pierre Mardon Oct 27 '12 at 03:02
  • What you're asking is essentially, "I have borrowed such-and-such code, and it's not working. Please tell me why." I don't see this as a viable or answerable question for this site until you've done some debugging to try to isolate the error. Sorry, but that's the way I see it: you've got your work cut out for you. It would be much different if this were you code, since you would understand it backwards and forwards and have a better idea of where the problem is. Keep at it, and you'll likely solve this or at least isolate it. – Hovercraft Full Of Eels Oct 27 '12 at 03:06
  • Nop. I spent hours on this bug, debugging and searching before asking. I can maybe precise what my problem is in the JNA context. I'll edit my post. – Pierre Mardon Oct 27 '12 at 03:09
  • For best results, you should create and post a *small* self-contained JNA program that reproduces this error. – Hovercraft Full Of Eels Oct 27 '12 at 03:10
  • I'm interested in JNA and have asked and answered a few questions on this subject on this site. Let me know if you create and post this program please. – Hovercraft Full Of Eels Oct 27 '12 at 03:27
  • @HovercraftFullOfEels thank you for encouraging me doing a better presentation of the problem, I added a 4-lines test code to reproduce my issue. – Pierre Mardon Oct 27 '12 at 03:38
  • Your four lines of code are missing the class declaration line. When I placed your line, `RECT rect = new RECT();` in a main method of an actual class, it ran and compiled just fine. – Hovercraft Full Of Eels Oct 27 '12 at 03:42
  • I'm really sorry, I forgot to paste the full code. I edited it in my post. And this test throws the same exception. – Pierre Mardon Oct 27 '12 at 03:48
  • Is this your first time working with JNA? Do you know if your current set up with JNA works? Consider deleting your two jar files -- platform.jar and jna.jar, and re-downloading and installing them. Are you using this with Eclipse or another IDE? – Hovercraft Full Of Eels Oct 27 '12 at 03:50
  • Yes, first time with JNA. No I don't know if my setup is ok. I already tried to redownload the two jars. And i'm running in eclipse using jre 1.7u9. – Pierre Mardon Oct 27 '12 at 03:51
  • According to your answer http://stackoverflow.com/questions/8858484/preparing-jna-for-use-in-eclipse , just adding the two jars to buildspace in eclipse should be sufficient. – Pierre Mardon Oct 27 '12 at 03:57
  • Yes, it works for me. Still, I'd make sure that your jar files are not corrupted. – Hovercraft Full Of Eels Oct 27 '12 at 03:59

2 Answers2

1

I don't know why but it works for me with JNA 3.4.0.

You can find it on MavenRepository http://mvnrepository.com/artifact/net.java.dev.jna

Thanks for your attention

Pierre Mardon
  • 727
  • 8
  • 25
1

The first line of the error

Exception in thread "main" java.lang.AbstractMethodError:

nearly always indicates a linkage error, that you're using incompatible versions of something.

In this specific case, it appears that platform.jar file released in JNA 3.5.0 was not properly updated.

technomage
  • 9,861
  • 2
  • 26
  • 40