Skip to content

Snappy1

  • Home
  • Android
  • What
  • How
  • Is
  • Can
  • Does
  • Do
  • Why
  • Are
  • Who
  • Toggle search form

[FIXED] java.lang.IllegalArgumentException: Failed to find storage device at null Android

Posted on November 11, 2022 By

Solution 1 :

Documentation for getExternalCacheDirs() clearly states that it returns an array of File containing:

File[] – the absolute paths to application-specific directories. Some
individual paths may be null if that shared storage is not currently
available. The first path returned is the same as
getExternalCacheDir().

So you need to check each entry in the returned array for null. In your case, you are getting a null entry in the array which causes this exception.

Problem :

I have a problem with memory access. The strangest thing is that this error is not even find in the internet. This bug happened on device with android 11.

The method with which the problem is related:

void  initSaveDataFolder(){
            if(SecurityPreferences.getAutoChosseFolder())
                for (File file : App.get().getExternalCacheDirs()) {
                    try {
                        if (Environment.isExternalStorageRemovable(file)) {
                            //System.out.println("getExternalCacheDirs is "+new Gson().toJson(file));
                            StatFs stat = new StatFs(file.getAbsolutePath());
                            long bytesAvailableInSdCard = (long)stat.getBlockSize() *(long)stat.getAvailableBlocks();
                            StatFs stat2 = new StatFs( App.get().getExternalCacheDir().getAbsolutePath());
                            long bytesAvailableInInternalMemory = (long)stat2.getBlockSize() *(long)stat2.getAvailableBlocks();
                            if(bytesAvailableInSdCard>bytesAvailableInInternalMemory)   SecurityPreferences.setIsSaveDataOnUsb(true);
                            else  SecurityPreferences.setIsSaveDataOnUsb(false);
                            System.out.println("memoryes is "+ bytesAvailableInSdCard+" "+bytesAvailableInInternalMemory);
                            SecurityPreferences.saveAutoChosseFolder(true);
                            break;
                        }
                    }catch (NullPointerException e){
                        SecurityPreferences.setIsSaveDataOnUsb(false); break;
                    }
                }
        }

Permissions related to storage access:

    <uses-permission
        android_name="android.permission.WRITE_EXTERNAL_STORAGE"
        tools_ignore="ScopedStorage" />
    <uses-permission android_name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android_name="android.permission.READ_INTERNAL_STORAGE" />

And Error stack trace:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.estvisx.ma/com.estvisx.ma.ui.splash.SplashActivity}: java.lang.IllegalArgumentException: Failed to find storage device at null
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3431)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:223)
       at android.app.ActivityThread.main(ActivityThread.java:7664)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
Caused by java.lang.IllegalArgumentException: Failed to find storage device at null
       at android.os.Environment.isExternalStorageRemovable(Environment.java:1202)
       at com.estvisx.ma.ui.splash.SplashActivity.initSaveDataFolder(SplashActivity.java:297)
       at com.estvisx.ma.ui.splash.SplashActivity.onCreate(SplashActivity.java:83)
       at android.app.Activity.performCreate(Activity.java:7994)
       at android.app.Activity.performCreate(Activity.java:7978)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1534)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3404)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3595)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2066)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:223)
       at android.app.ActivityThread.main(ActivityThread.java:7664)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)

I tried to search about this problem whole day, but i didnt find anything. I just have no idea.

READ  [FIXED] android - WiFiP2PManager, OnPeersAvailable, DeviceList.Count zero - always
Powered by Inline Related Posts

Comments

Comment posted by blackapps

have a problem with memory access.

Android Tags:android, android-file, android-fileprovider

Post navigation

Previous Post: Do you have to pay for MyNetDiary?
Next Post: [FIXED] Simple Cucumber Test is not running on Sample Android Project

Related Posts

[FIXED] android – How to .RequestFocus on last added EditView item in a cardview within a recylerview? Android
[FIXED] python – Failure while dumping the provider: java.io.IOException: Timeout Android
[FIXED] api – Downgrade Android SDK from 29 to 21 Android
[FIXED] java – why cant my bottom navigation bar be shown? Android
[FIXED] android – Launch new activity in AsyncTask in Kotlin Android
[FIXED] group by – Trouble with SQLite Query/Subquery Android

Archives

  • March 2023
  • February 2023
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuándo
  • ¿Cuántas
  • ¿Cuánto
  • ¿Qué
  • Android
  • Are
  • At
  • C'est
  • Can
  • Comment
  • Did
  • Do
  • Does
  • Est-ce
  • Est-il
  • For
  • Has
  • Hat
  • How
  • In
  • Is
  • Ist
  • Kann
  • Où
  • Pourquoi
  • Quand
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welchen
  • Welcher
  • Welches
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Who's
  • Why
  • Wie
  • Will
  • Wird
  • Wo
  • Woher
  • you can create a selvedge edge: You can make the edges of garter stitch more smooth by slipping the first stitch of every row.2022-02-04
  • you really only need to know two patterns: garter stitch

Recent Posts

  • What is the rising action in Julius Caesar?
  • How do you secure a rope to itself?
  • Does waterproof laminate scratch easily?
  • What makes a building prewar?
  • What can you learn in a month without alcohol?

Recent Comments

No comments to show.

Copyright © 2023 Snappy1.

Powered by PressBook Grid Dark theme