Link to home
Start Free TrialLog in
Avatar of polkadot
polkadot

asked on

URGENT! java.lang.NullPointerException with File object

why would this give me java.lang.NullPointerException ?

File directory = new File("C:/Temp");
File[] fileList = directory.listFiles();

is there something else I should look for in the code?
Avatar of polkadot
polkadot

ASKER

btw, I get the error in run time, not compile time ...
ASKER CERTIFIED SOLUTION
Avatar of dttri
dttri
Flag of Viet Nam image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
C:/Temp will work fine (as long as the dir exists), I just tested it.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:/

C:/Temp is a directory ... and it works that way ... so I'll give you all good grades :)

but not this way:

public class A{

File directory;

public A(File d)
{  directory = d; }

public void M()
{ File[] fileList = directory.listFiles();}


can you explain why, that when I want it to remeber the directory in the method, It forgets ?


Avatar of CEHJ
>>This may resolve the problem.

It won't

>>can you explain why, that when I want it to remeber the directory in the method, It forgets ?

Maybe - if you post the rest of the code for class A
 You should post your solution, not just comment CEHJ.
>>You should post your solution

As i mentioned, polkadot will have to post more code