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]

> 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
> > 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.
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)