У меня есть ошибка в:
Я не понимаю, потому что, если у меня уже есть все разрешения.
Проверка, были ли получены разрешения.
Ошибка: java.lang.NullPointerException: попытка получить длину нулевого массива
Вам необходимо запросить разрешение перед любой операцией динамически, как показано ниже
Из file.Java о listFiles() :
Так как вы не получите SecurityException и список null ,
единственные другие варианты:
- этот абстрактный путь не обозначает каталог
- возникает ошибка ввода/вывода
Вы должны проверить javadoc для метода listFiles().
Нуль будет возвращен, если файл не является каталогом. Чтобы предотвратить нулевой указатель, вы можете сначала проверить объект файла с помощью isDirectory() и, если false, не выполнять цикл.
Посмотрите другие вопросы по метке android или Задайте вопрос
Please Help I am newbie and I am getting am getting this error? while I start the App, I request for Storage Permission but after that the app crashes and gives me this error :- Attempt to get Length of null Array. Please Help.
This is my ImageAdapter
Here is my Image Fragment

1 Answer 1
The file[] is null, therefore this statement return file.length; or any other involving that variable will fail. Also do use exception handling to handle files existence in your. Like FileNotFound for example.
Also try this String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
Use this instead to get a handle to the file.
Syntax for calling getExternalFilesDir, it depends on a context.
Comments
Copy link Quote reply
coolguy001tv commented Jan 22, 2019
Steps to Reproduce
1.crash log shows this error
Expected Behavior
Actual Behavior
crashed, here’s the log:
Environment
react-native-code-push version:4.0.0-beta
react-native version:0.46.0 (I know it’s so old, we’re trying updating)
iOS/Android/Windows version: android
Does this reproduce on a debug build or release build? release
Does this reproduce on a simulator, or only on a physical device? physical device