• 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

What am I doing wrong (one line of code) ...

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is wrong with this line of code?

 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is that list() is an instance method in the File class, which means that you have to call the method list() using a reference to an instance of a File.
 
Jesse Crockett
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean something like this peculiar bit:



I've been trying to figure this out for several hours.
 
Keith Lynn
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. The list() method returns a String array of the filenames in the directory represented by the File object or null if the File object doesn't represent a directory.

What are you trying to do?
[ December 09, 2006: Message edited by: Keith Lynn ]
 
Jesse Crockett
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for helping. Somehow I have a way of figuring out my problem right before my question gets answered here. That's ultimately to my benefit, of course...

thanks :-)
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like this is resolved, but just to summarize...

If a method is static, then it belongs to the class. You can (and should) call it using the class name.

ClassName.staticMethod();

If a method is not static, then it is an instance method, and it belongs to a particular instance of that class. In this case, you must create an instance in order to call the method.

ClassName myInstance = new ClassName();
myInstance.instanceMethod();
 
reply
    Bookmark Topic Watch Topic
  • New Topic