permaculture playing cards*
The moose likes I/O and Streams and the fly likes WatchService API Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "WatchService API" Watch "WatchService API" New topic
Author

WatchService API

meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305


Registering:test
Exception in thread "main" java.lang.NullPointerException
at sun.nio.fs.WindowsPath.register(WindowsPath.java:847)
at sun.nio.fs.AbstractPath.register(AbstractPath.java:104)
at WatchDirTree.registerPath(WatchDirTree.java:42)
at WatchDirTree.preVisitDirectory(WatchDirTree.java:28)
at WatchDirTree.preVisitDirectory(WatchDirTree.java:18)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:192)
at java.nio.file.FileTreeWalker.walk(FileTreeWalker.java:69)
at java.nio.file.Files.walkFileTree(Files.java:2591)
at java.nio.file.Files.walkFileTree(Files.java:2624)
at WatchDirTree.registerTree(WatchDirTree.java:47)
at WatchDirTree.watchDirTree(WatchDirTree.java:52)
at WatchDirTree.main(WatchDirTree.java:90)
test directory exists.couldn't figure out where is problem


My one regret in life is that I am not someone else.
- Woody Allen
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1939
    
  28
Just before line 42 print out the values of Path, watch_service etc to see what they are, also convert the Path to a File and call it's exists() method printing out the result.
meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305

Tony Docherty wrote:Just before line 42 print out the values of Path, watch_service etc to see what they are, also convert the Path to a File and call it's exists() method printing out the result.

watch_service is null
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1939
    
  28
Well there's your answer. Make sure it is set to a value before the method is called.
meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305

i could not figure out why watch_service is null at 42 while at 51 i assigned object.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1939
    
  28
Does it run line 42 before 51?
Are there different variables called watch_service (which is badly named BTW, stick to Java naming conventions and don't use underscores), ie local, instance etc.
Have you created another Object which is running it's line 42 before it's line 51 has run.
meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305

Tony Docherty wrote:Does it run line 42 before 51?


No, 42 will never run before 51.

Are there different variables called watch_service (which is badly named BTW, stick to Java naming conventions and don't use underscores), ie local, instance etc.
Have you created another Object which is running it's line 42 before it's line 51 has run.

No, there is only single object.

I tried to know but don't know where is problem.i leave it for now.Anyways thank you very much for your time.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1939
    
  28
No, there is only single object.

Really, so what does line 46 do?
meeta gaur
Ranch Hand

Joined: Dec 05, 2012
Posts: 305

Tony Docherty wrote:
No, there is only single object.

Really, so what does line 46 do?

OMG Thank you very much you saved me.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1939
    
  28
Debugging advice:
When debugging you mustn't assume anything.
There's no point in just looking at the code and saying yes that does exactly what it's supposed to do when clearly it doesn't. You have to use a debugger or add print statements to find out if the values are variables are what you think they should be, add print statements to establish the order certain lines run in etc.

Only once you have tried to debug it yourself should you ask here for help. Debugging skills need to be learned and are a vital part of a programmers armory. And when you do ask a question, every suggestion someone makes needs to be checked thoroughly and just looking at the code isn't a thorough check. Generally it will involve stepping thorough the code with a debugger or adding print statements. And when someone suggests something like have you got more than one object don't just say "no I don't". Do a find on your code to look for all instances of the class name to check you haven't accidentally created more objects.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: WatchService API
 
Similar Threads
Listing all in a root (39 Line working code)
Watching directory for changes Java7
Keep track of file name changes
No Output
FileVisitResult