jacobian
jacobian

Reputation: 327

error exception access violation in JNotify

I am trying to implement JNotify. but I am getting a bit weird error messages when I compiled the program. I get the sample code from this site ttp://jnotify.sourceforge.net/sample.html

as an info, JNotify is used for directory monitoring and this is how my source code looks like.

this is the content of the class 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);
    }
  }
}

then this is the main class that named 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");
    }
}

but why did the error went like this? I had screenshot the error so that you can see it by clicking on this link

has any of you ever experience this type of error? any help would be appreciated though. thanks

Upvotes: 3

Views: 1099

Answers (3)

NoNaMe
NoNaMe

Reputation: 6232

it ask for jNotify.dll file, make sure that you have placed that file to the window or in jre/bin or jdk/bin. and then try it will start working.

Upvotes: 0

Daniel
Daniel

Reputation: 28084

We had the same problems. Because we used JNA anyways, we just used the FileMonitor example from this framework. Works like a charm.

Upvotes: 0

Jim Garrison
Jim Garrison

Reputation: 86774

JNotify surely uses JNI to interface with the OS-dependent notification APIs. Looks like there's a bug in JNotify. Have you tried asking on the JNotify forum on SourceForge?

Upvotes: 2

Related Questions