首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >运行jnotify示例代码时的访问冲突

运行jnotify示例代码时的访问冲突
EN

Stack Overflow用户
提问于 2015-04-08 13:45:29
回答 1查看 217关注 0票数 0

我试图从http://jnotify.sourceforge.net/sample.html运行修改后的代码示例,但得到了以下错误:

Java运行时环境检测到了一个致命错误:

代码语言:javascript
复制
 EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d980b1f, pid=7308, tid=10568

 JRE version: 6.0_45-b06
 Java VM: Java HotSpot(TM) Client VM (20.45-b01 mixed mode windows-x86 )
 Problematic frame:
 V  [jvm.dll+0xa0b1f]

我以前见过这种情况,在未修改的代码示例中没有对监听器的引用,垃圾收集器也删除了它。但在这里,我要提到它。有人看到问题了吗?

代码语言:javascript
复制
public static void sample() throws Exception {
    JNotifyListener listener = (JNotifyListener) new Listener();
    // path to watch
    String path = System.getProperty("D:/Pathname");

    // 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,
            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.
    }
}

static 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);
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-08 14:36:43

您的代码中有一个bug。;-)

替换

代码语言:javascript
复制
String path = System.getProperty("D:/Pathname");

通过

代码语言:javascript
复制
String path = "D:/Pathname";
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29516468

复制
相关文章

相似问题

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