• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

WatchService API

 
Ranch Hand
Posts: 305
Tomcat Server Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Bartender
Posts: 3323
86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 305
Tomcat Server Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well there's your answer. Make sure it is set to a value before the method is called.
 
meeta gaur
Ranch Hand
Posts: 305
Tomcat Server Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i could not figure out why watch_service is null at 42 while at 51 i assigned object.
 
Tony Docherty
Bartender
Posts: 3323
86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 305
Tomcat Server Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3323
86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

No, there is only single object.


Really, so what does line 46 do?
 
meeta gaur
Ranch Hand
Posts: 305
Tomcat Server Notepad Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 3323
86
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic