0

I am trying to fill the internal storage memory . But my app crashes everytime I run it.

My logcat error is:

java.lang.NoSuchMethodError: android.os.Environment.isExternalStorageRemovable
at com.symbol.fillexternalmemory.MainActivity.getExternalSdCardSize(MainActivity.java:175)
at com.symbol.fillexternalmemory.MainActivity.onCreate(MainActivity.java:44)

My MainActivity.java is:

protected static Long getExternalSdCardSize() {
        File storage = new File("/storage");
        String external_storage_path = "";
        Long size = null;

        if (storage.exists()) {
            File[] files = storage.listFiles();

            for (File file : files) {
                if (file.exists()) {
                    try {
                        if (Environment.isExternalStorageRemovable(file)) {
                            // storage is removable
                            external_storage_path = file.getAbsolutePath();
                            break;
                        }
                    } catch (Exception e) {
                        Log.e("TAG", e.toString());
                    }
                }
            }
        }

        if (!external_storage_path.isEmpty()) {
            File external_storage = new File(external_storage_path);
            if (external_storage.exists()) {
                size = totalSize(external_storage);
            }
        }
        return size;
    }

And my build.gradle file is:

android {
    compileSdkVersion 23
    buildToolsVersion "27.0.3"
    defaultConfig {
        applicationId "com.symbol.fillexternalmemory"
        minSdkVersion 22
        targetSdkVersion 23
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    productFlavors {
    }
}

dependencies {
    compile 'com.android.support:support-v4:23.4.0'
}

Can someone tell me why is it that the app crashes everytime? I have referred pervious answers to similar question but couldn't find a proper solution that helped?

vinny kinger
  • 11
  • 1
  • 4
  • have u seen this link https://stackoverflow.com/questions/20858972/getting-java-lang-nosuchmethoderror-android-os-fileutils-getfatvolumeid-in-4-2/20859031#20859031 – duggu Feb 20 '18 at 06:10
  • Try clean + rebuild + run – VVB Feb 20 '18 at 06:23
  • Possible duplicate of [How do I fix a NoSuchMethodError?](https://stackoverflow.com/questions/35186/how-do-i-fix-a-nosuchmethoderror) – Vikrant Kashyap Feb 20 '18 at 06:35
  • I would suggest you to use **Class.getDeclaredMethods()** to check if the method exists or not – Arpan Sarkar Feb 20 '18 at 06:49

0 Answers0