• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Jesse Crockett
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is wrong with this line of code?

 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • 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
  • 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: 2409
  • Mark post as helpful
  • send pies
  • 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
  • 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 :-)
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • 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();
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!