首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >JNotify中出现错误异常访问冲突

JNotify中出现错误异常访问冲突
EN

Stack Overflow用户
提问于 2010-10-01 23:52:37
回答 3查看 1.1K关注 0票数 3

我正在尝试实现JNotify。但是当我编译这个程序时,我收到了一些奇怪的错误信息。我从这个站点获取示例代码:ttp://jnotify.sourceforge.net fy.sourceforge.net/sample.html

作为信息,JNotify用于目录监控,这就是我的源代码的样子。

这是类watching.java的内容

代码语言:javascript
复制
import net.contentobjects.jnotify.JNotifyListener;
import net.contentobjects.jnotify.JNotify;


public class watching{

public void watching(String s) throws Exception {
    // path to watch
    String path = System.getProperty(s);

    // watch mask, specify events you care about,
    // or JNotify.FILE_ANY for all events.
    int mask = JNotify.FILE_CREATED  | 
               JNotify.FILE_DELETED  | 
               JNotify.FILE_MODIFIED | 
               JNotify.FILE_RENAMED;

    // watch subtree?
    boolean watchSubtree = true;

    // add actual watch
    int watchID = JNotify.addWatch(path, mask, watchSubtree, new Listener());

    // sleep a little, the application will exit if you
    // don't (watching is asynchronous), depending on your
    // application, this may not be required
    Thread.sleep(1000000);

    // to remove watch the watch
    boolean res = JNotify.removeWatch(watchID);
    if (!res) {
      // invalid watch ID specified.
    }
  }
  class Listener implements JNotifyListener {
    public void fileRenamed(int wd, String rootPath, String oldName,
        String newName) {
      print("renamed " + rootPath + " : " + oldName + " -> " + newName);
    }
    public void fileModified(int wd, String rootPath, String name) {
      print("modified " + rootPath + " : " + name);
    }
    public void fileDeleted(int wd, String rootPath, String name) {
      print("deleted " + rootPath + " : " + name);
    }
    public void fileCreated(int wd, String rootPath, String name) {
      print("created " + rootPath + " : " + name);
    }
    void print(String msg) {
      System.err.println(msg);
    }
  }
}

然后,这是名为nowwatch.java的主类

代码语言:javascript
复制
public class nowwatch
{
    public static void main(String[] args) throws Exception 
    {
        System.out.println("Hello World!");
        watching hello = new watching();
        hello.watching("C:/Users/Raden/Documents/Downloads");
    }
}

但是为什么会出现这样的错误呢?我已经截取了错误的屏幕,以便您可以通过单击此link来查看它

你们当中有没有人遇到过这种类型的错误?不过,任何帮助都将不胜感激。谢谢

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2010-10-02 01:19:50

JNotify肯定会使用JNI来与操作系统相关的通知API进行交互。看起来JNotify里有个bug。你有没有试过在SourceForge上的JNotify论坛上提问?

票数 2
EN

Stack Overflow用户

发布于 2012-02-15 21:33:40

我们也有同样的问题。因为我们无论如何都要使用JNA,所以我们只使用了这个框架中的FileMonitor示例。就像一种护身符。

票数 0
EN

Stack Overflow用户

发布于 2012-07-30 18:22:56

如果系统要求提供jNotify.dll文件,请确保已将该文件放到窗口或jre/bin或jdk/bin中。然后试一试,它就会开始工作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3840844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档