0
我試圖從http://jnotify.sourceforge.net/sample.html 運行修改後的代碼示例,但收到以下錯誤jnotify示例代碼時:訪問衝突運行
已經由Java運行時環境檢測到致命錯誤:
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]
我之前看到過這種情況,因爲在未修改的代碼示例中沒有引用該偵聽器,並且垃圾收集器已將其刪除。但我在這裏提到它。有沒有人看到這個問題?
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);
}
}
哦,是的,謝謝,請您從您的文章中刪除路徑信息。我之前插入了「匿名」代碼片段,但未將其識別爲代碼片段。當我做對了,我粘貼了非匿名版本。感謝您向我指出這一點。 – floquet22
是的,它現在適合我。只要我有我的聲譽上漲,以便我可以給你的帖子大拇指我會這樣做。 – floquet22
@ floquet22你應該已經能夠接受答案,如果它解決了你的問題。 – SubOptimal