Strange Error

I have this program that sets up directores and checks if a file is located in that directoy. And It works fine 99.9 percent of the time except when the directory entered is AUX.

The Code looks like this:

privateboolean checkFileExist(){

boolean exist=false;

file=new File(saveLocation);

fileList=file.listFiles();

System.out.println(saveLocation);

for(int i=0; i< fileList.length;i++){//Where the error is CreateXLS.java:1029

int choice;

if(fileList[i].getName().equals(saveName)){

choice=JOptionPane.showConfirmDialog(null,"File "+saveName+" already exist.\n Replace File?","Replace File", JOptionPane.YES_NO_OPTION);

if(choice==0){

exist=false;

}

else{

exist=true;

}

}

}

return exist;

}

The path is:

C:\Documents and Settings\ddixon\My Documents\test\AUX\TOSHIBA\

and the error message is

java.lang.NullPointerException

at Data.CreateXLS.checkFileExist(CreateXLS.java:1029)

And it works every other time except the \AUX\ is the directory. Any ideas why?

Message was edited by:

blackmage

[2001 byte] By [blackmagea] at [2007-11-27 10:07:33]
# 1
I would say try making your own aux directory somewhere else. I suspect it doesn't have to do with any directory name AUX, just that particular one.
Aknibbsa at 2007-7-13 0:43:51 > top of Java-index,Java Essentials,Java Programming...
# 2

> for(int i=0; i< fileList.length;i++)

Not completely sure but isn't the A index 0? so you would have to do

for(int i=0; i<= fileList.lenght; i++)?

I'm just a novice so i'm not sure

jk.... I'm thinking of something else

Message was edited by:

mark07

mark07a at 2007-7-13 0:43:51 > top of Java-index,Java Essentials,Java Programming...
# 3
Do you know that file already has an exists() method?
BigDaddyLoveHandlesa at 2007-7-13 0:43:51 > top of Java-index,Java Essentials,Java Programming...
# 4
> Do you know that file already has an exists() method?Yea I know but I felt like doing it this way. But I'm still not sure why its doing this....
blackmagea at 2007-7-13 0:43:51 > top of Java-index,Java Essentials,Java Programming...
# 5

> > Do you know that file already has an exists() method?

>

> Yea I know but I felt like doing it this way.

I usually lie down until such feelings pass.

> But I'm still not sure why its doing this....

From the API for listFiles:

If this abstract pathname does not denote a directory, then this method returns null.

BigDaddyLoveHandlesa at 2007-7-13 0:43:51 > top of Java-index,Java Essentials,Java Programming...
# 6
Does AUX exist on the filesystem?Is it a directory?
maple_shafta at 2007-7-13 0:43:51 > top of Java-index,Java Essentials,Java Programming...
# 7

I decided to try the easy way and it still fails:

private boolean checkFileExist() {

boolean exist=false;

file=new File(saveName);

//fileList=file.listFiles();

//System.out.println(saveLocation);

//for(int i=0; i< fileList.length;i++){

int choice;

if(file.exists()==true){

choice=JOptionPane.showConfirmDialog(null, "File "+saveName+" already exist.\n Replace File?", "Replace File", JOptionPane.YES_NO_OPTION);

if(choice==0){

exist=false;

}

else{

exist=true;

}

}

return exist;

}

With the error message:

java.io.FileNotFoundException: C:\Documents and Settings\jjohnson\My Documents\test\AUX\DENON\AUX 222 (DENON) RBG1.xls (The system cannot find the path specified)

blackmagea at 2007-7-13 0:43:51 > top of Java-index,Java Essentials,Java Programming...
# 8
> Does AUX exist on the filesystem?> > Is it a directory?No, if the directory does not exist, it is made.And I works for every other directory , anywhere even on different drives, except when AUX is used.
blackmagea at 2007-7-13 0:43:51 > top of Java-index,Java Essentials,Java Programming...