• 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

whats wrong with this??

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have written a program that should display all the .class files in the directory and the subdirectories of the directory given at the command line as an input.

The program is compiling fine but it does not give any output. I am not able to figure out why... Pls help!!!



Thanks...
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, the main loop does nothing unless the file is a directory, right? The only print statement is the one that prints the absolute path of a directory. And then because you've used the filename filter, you know that the only files in "filenames" must have names that end with ".class". So unless you've got a directory named <something>.class, this program isn't going to print anything.
 
Sabrina Kaur
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ernest,

I replaced the isDirectory() with the isFile(), but the program still does not give the expected output.

I also tried to return true from the accept() method as:


When I did this, it prints all the files in the directory given on the command line.
So, does this mean that the line:

return filename.endsWith(ext); is not returning the true value for any filename???

I made sure that I tried with the directory which at least had a .class file.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, another problem I see is that the constructor has a parameter named "ext" and there's also a member named "ext"; the assignment you make in the constructor goes to the parameter, not to the member, so the member "ext" is always null. Changing the name of the constructor parameter, or using "this.ext = ...", would fix that, and then you'll be on your way. Then you'll start to get some NullPointerExceptions, as calling File.list() when the File isn't a directory returns null.
reply
    Bookmark Topic Watch Topic
  • New Topic