-1

I am trying to get all the text files from a location then checking with every file name (ACMEMM_ADDITIONAL_ATTRIBUTE_02172015_075611) then trimming it to 02172015_075611.After doing this I am inserting every file name into string array , but when I am doing this I am getting Null pointer exception at mr[i]=s;

import java.io.File;

public class dog{
public void listFiles(){
File directory = new File("C://Users//422405//Desktop//Az_Support_Process//New folder (3)");

//get all the files from a directory

File[] fList = directory.listFiles();
System.out.println(fList.length);
int count=0;
int i=0;
String s;
String [] mr=null;
for (File file : fList){

if (file .isFile()){
count++;

s=file.getName().replaceAll("[^0-9]", "");;
System.out.println(s);

mr[i]=s;

i++;
//System.out.println(i);
}}

//System.out.println(mr.length);
if(count==20){

}
System.out.println(count);
}

public static void main(String[] args)
{
System.out.println("Hello");
dog d=new dog();
d.listFiles();

}

}
Cœur
  • 32,421
  • 21
  • 173
  • 232
Mohit Darmwal
  • 209
  • 5
  • 15

1 Answers1

0

You have to initialize the mr array:

String [] mr = new String[fList.length];

Read More about this exception here and how to fix.

Community
  • 1
  • 1
Salah
  • 8,098
  • 3
  • 20
  • 39