代码是:
String[] absoluteFilePath = null;
try {
File file = new File(filePath);
if( file.isDirectory()) {
System.out.println("文件夹");
String[] fileList = file.list();
for (int i = 0; i < fileList.length; i++) {
File fullFile = new File(filePath + "\" + fileList[i]);
absoluteFilePath[i] = fullFile.getAbsolutePath();
System.out.println("absoluteFilePath=" + absoluteFilePath[i]);
}
}
}
然后会在 absoluteFilePath[i] = fullFile.getAbsolutePath(); 这一行报java.lang.NullPointerException
File fullFile = new File(filePath + "\" + fileList[i]);//这里的单斜杠是不是要改成双斜杠;
如果回答对您有帮助,请采纳
String[] absoluteFilePath = null;
……
absoluteFilePath[i] = fullFile.getAbsolutePath();
你没有初始化就是用这个数组了