5

I am working with sample code from another StackOverflow post - Java - How to take a screenshot fast, but I'm having some issues.

I downloaded the JNA files from its Github repository, then copied the file inside the JAR file and put it into the same folder where my program is. But when I try to compile my program, it give me a lot of error as shown at below:

C:\Users\windows\Desktop\testPrintScreen>javac JNAScreenShot.java
JNAScreenShot.java:12: error: package com.sun.jna.platform.win32 does not exist
import com.sun.jna.platform.win32.W32API;
                             ^
JNAScreenShot.java:129: error: package com.sun.jna.platform.win32 does not exist
interface GDI32 extends com.sun.jna.platform.win32.GDI32 {

                                              ^
JNAScreenShot.java:58: error: cannot find symbol
bufferedImageFromBitmap(GDI32.HDC        blitDC,
                             ^
symbol:   class HDC
location: interface GDI32
JNAScreenShot.java:59: error: cannot find symbol
                        GDI32.HBITMAP    outputBitmap,
                             ^
symbol:   class HBITMAP
location: interface GDI32
JNAScreenShot.java:60: error: cannot find symbol
                        GDI32.BITMAPINFO bi) {
                             ^
 symbol:   class BITMAPINFO
 location: interface GDI32
JNAScreenShot.java:151: error: package com.sun.jna.platform.win32 does not exist
interface User32 extends com.sun.jna.platform.win32.User32 {

Does anyone know what is happening? Is it the import part that is causing problems? These are my imports:

import com.sun.jna.Native;
import com.sun.jna.platform.win32.W32API;
import com.sun.jna.win32.W32APIOptions;
Community
  • 1
  • 1
Eric
  • 401
  • 4
  • 13
  • 21
  • Did you grab all the files from the repository? Also, its better to download the project you linked separately and build it into a JAR, then link that JAR to your project. – Perception Apr 27 '12 at 03:36

1 Answers1

1

I don't have a Windows machine at the moment, but a variation of the below should work just fine. In a command window change to a convenient directory, then:

git clone https://github.com/twall/jna.git
cd jna
ant
cd dist
pwd

Take a note of the last path, you need to include that in your classpath when compiling your JNA program. You may also need to include some of the other JAR's in the dist folder.


* EDIT * Based off your additional comments it would seem your code is using older JNA API's. Refer to this SO post for more information on how to get around that problem - JNA W32API - Where are they?.

Community
  • 1
  • 1
Perception
  • 79,279
  • 19
  • 185
  • 195
  • thanks for the reply but windows don't jave git clone .. it is linux command right .. but anyway .thanks .. – Eric Apr 27 '12 at 03:57
  • Yes, which is why I stated that a variation of the commands would be needed. On Windows you can use [cygwin](http://www.cygwin.com/), and then you can pretty much just run what I have in my answer. Or you can download the code using your favorite [Windows Git client](https://www.google.com/search?sourceid=chrome&ie=UTF-8&q=windows+git+clients). – Perception Apr 27 '12 at 03:59
  • i think i know what problem is that .. the W32API is missing , do you know where to find it ? i have found a few but it is in java file. So i compile it but it give me a lot of error .. – Eric Apr 27 '12 at 05:39