English 中文(简体)
为什么我得到这些错误?
原标题:why do i get these errors?
  • 时间:2012-05-22 06:18:05
  •  标签:
  • java

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());
    }
}

这是给定的"的代码, http://code.google.com/p/jnativehook/wiki/examples" rel="nofollow"。 我下载了这个代码, 然后在我的项目中使用了 http://code.google.com/p/jnativehook/ downloads/list" rel="no follow" >JativeHost 库 。 但我得到以下错误 :

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

第一个错误,我还导入了GlobScreen类。

为什么我得到第二个错误? “ 强” 但当我在使用该方法之前添加一个 Override 注释时, IDE 给出了一个错误, 表示该方法不会从超级类型上取代或执行 。

最佳回答

所有事情都很好!我认为可能出错的一件事是 你可能使用的图书馆版本 来对抗你复制和粘贴的代码! 使用下面标记的图书馆 。 < a href="http://code.google.com/ p/ jnativehook/ downloads/ list" rel="nofollow noreferrer" 您可以从这里下载

""https://i.sstatic.net/gpojp.jpg" alt="在这里输入图像描述"/ >

从评论中猜想您正在使用Netbeans。 添加此罐头文件到您的库中 。

问题回答

如果使用日食,请尝试从这样的空课开始:

public class GlobalKeyListenerExample implements NativeKeyListener {
}

您应该在声明上出错, 并且快速修正可以执行抽象的方法。 执行快速修正并查看它是否在事后编译( 通常应该) 。 然后您可以继续并添加逻辑 。

最有可能的是,您所说的被推翻的方法有与基类不同的签名。 因此, 您的方法不会被视为被推翻, 而是一个新的超载版本。 验证该方法的签名是否正确 。

如果您正在使用JDK 1. 5, @Override 只能用于基础类的压倒性方法, 而不是用于使用接口的方法 。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签