0

Hi I have read the questions that written before about this subject but I did not found the answer that related to my question. when I have run my code in android studio it was appeared this error of "Caused by: java.lang.NullPointerException: Attempt to get length of null array"

Here is the line that cause of the error in my code for the main activity :

Blockquote

File[] files= root.listFiles();

ash
  • 9
  • 2

2 Answers2

0

Your 'singlefile' may 'isDirectory', but it`s empty inside;

That cause your error on this line

 File[] files= root.listFiles();
Josh.M
  • 103
  • 4
  • Deividi Cavarzan, Bartłomiej Semańczyk, Frank N. Stein ... why all of you doing that, all of you marked my Q as duplicate I know there are some Q has the same title but I have read it, it was different to my question, so please if there is no one have answer please just ignore my Q, instead of annoying me with some messages like that. – ash Nov 25 '15 at 20:07
  • Thanks for your replying @Josh.M – ash Nov 25 '15 at 20:08
0

you are getting null pointer exception because you don't have permission to read from Environment.getExternalStorageDirectory()

Add this permission in manifest

uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"

Nikhil
  • 650
  • 1
  • 11
  • 28
  • I have already added the permission. so the problem it is not with the permission – ash Nov 25 '15 at 20:01