gpt4 book ai didi

java - JNotify 中的错误异常访问冲突

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:40:12 25 4
gpt4 key购买 nike

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

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

这是类watching.java的内容

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 的主类

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 查看它

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

最佳答案

JNotify 肯定使用 JNI 来与操作系统相关的通知 API 进行交互。看起来 JNotify 中有一个错误。您是否尝试过在 SourceForge 上的 JNotify 论坛上提问?

关于java - JNotify 中的错误异常访问冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3840844/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com