Why am I getting these errors?

The code:

package keylogger;

import org.jnativehook.GlobalScreen;
import org.jnativehook.NativeHookException;
import org.jnativehook.keyboard.NativeKeyEvent;
import org.jnativehook.keyboard.NativeKeyListener;

public class GlobalKeyListenerExample implements NativeKeyListener {
    public void nativeKeyPressed(NativeKeyEvent e) {
            System.out.println("Key Pressed: " + NativeKeyEvent.getKeyText(e.getKeyCode()));

            if (e.getKeyCode() == NativeKeyEvent.VK_ESCAPE) {
                    try {
                            GlobalScreen.unregisterNativeHook(); // LINE 18
                    }
                    catch (NativeHookException ex) {
                            System.err.println("You cannot call unregisterNativeHook() from the native dispatch thread.");
                    }
            }
    }


    public void nativeKeyReleased(NativeKeyEvent e) {
            System.out.println("Key Released: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
    }

    public void nativeKeyTyped(NativeKeyEvent e) {
            System.out.println("Key Typed: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
    }


    public static void main(String[] args) {
            try {
                    GlobalScreen.registerNativeHook(); // LINE 38
            }
            catch (NativeHookException ex) {
                    System.err.println("There was a problem registering the native hook.");
                    System.err.println(ex.getMessage());
                    ex.printStackTrace();
            }

            //Construct the example object and initialze native hook.
            GlobalScreen.getInstance().addNativeKeyListener(new GlobalKeyListenerExample());
    }
}

This is the same code as here in the Google code . I downloaded and then used the JNativeHost library in my project. But I get the following errors:

Cannot find unregisterNativeHook,registerNativeHook. //(line 18,38)
The IDE also says GlobalKeyListenerExample is not abstract and doesn't override abstract method keyReleased. 

To the first error, the methods are defined here, and they are proprietary methods , and I also imported the GlobalScreen class.

And why am I getting a second error when I have already redefined it? But when I add the annotation @Overridebefore this method, the IDE gives an error saying that the method does not override or does not implement from the supertype.

+3
source share
4 answers

! , , , , - , , ! .

enter image description here

, , netbeans. jar .

+2

eclipse, :

public class GlobalKeyListenerExample implements NativeKeyListener {
}

, . , ( , ). .

+2

Most likely, the method that you say you redefined has a different signature than in the base class. Thus, your method is not considered overridden, but is a new overloaded version. Verify that the method signature is correct.

0
source

If you use JDK 1.5, @Override can only be used when overriding methods from base classes, and not when implementing methods from interfaces.

0
source

All Articles