Through Android SDK and AVD Manager I have created an AVD of android3.0 version with size option as 1024MiB. In my application class I have asked to create a directory so that I can cache images. But I get error over there as
09-07 15:32:31.253: ERROR/AndroidRuntime(380): Caused by: java.lang.IllegalStateException: Unable to create nomedia file.
My code is:
File baseDirectory = new File(Environment.getExternalStorageDirectory(), "myapp");
File storageDirectory = new File(baseDirectory, "imagecache");
File nomediaFile = new File(storageDirectory, NOMEDIA);
nomediaFile.createNewFile();
Error comes over in the 4th line. Could anyone please help me out. I am new to honeycomb. Thanks in advance.
As others have suggested, you should have mkdirs()
to ensure your directory path is there. You also need the WRITE_EXTERNAL_STORAGE
permission.