I am getting the following message in android LogCat
03-20 01:45:03.362: WARN/System.err(369): java.io.FileNotFoundException: /mnt/sdcard/LazyList/-2012431329 (No such file or directory)
03-20 01:45:03.362: WARN/System.err(369): at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
03-20 01:45:03.372: WARN/System.err(369): at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
03-20 01:45:03.382: WARN/System.err(369): at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
03-20 01:45:03.382: WARN/System.err(369): at java.io.FileOutputStream.<init>(FileOutputStream.java:66)
03-20 01:45:03.392: WARN/System.err(369): at com.ImageLoaders.ImageLoader.getBitmap(ImageLoader.java:86)
For downloading images in android emulator I have added internet permission in androidManifest.xml file, but looks like it is not working. I have also given 10MB space to android emulator as well.
any one guide me what could be the problem? thanks in advance.
How to Fix FileNotFoundException. Since FileNotFoundException is a checked exception, a try-catch block should be used to handle it. The try block should contain the lines of code that can throw the exception and the catch block should catch and handle the exception appropriately.
Class FileNotFoundException Signals that an attempt to open the file denoted by a specified pathname has failed. This exception will be thrown by the FileInputStream , FileOutputStream , and RandomAccessFile constructors when a file with the specified pathname does not exist.
FileOutputStream(File file) Creates a file output stream to write to the file represented by the specified File object. FileOutputStream(File file, boolean append) Creates a file output stream to write to the file represented by the specified File object.
FileNotFoundException occurs at runtime so it is a checked exception, we can handle this exception by java code, and we have to take care of the code so that this exception doesn't occur.
I solved this problem adding permissions:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
ImageLoader Constructor should be change to this.
public ImageLoader(Context context) {
// Make the background thead low priority. This way it will not affect
// the UI performance
photoLoaderThread.setPriority(Thread.NORM_PRIORITY - 1);
// Find the dir to save cached images
if (android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED))
cacheDir = new File(context.getCacheDir(), "LazyList");
else
cacheDir = context.getCacheDir();
if (!cacheDir.exists())
cacheDir.mkdirs();
}
By default it is like this
cacheDir = new File(android.os.Environment.getDataDirectory(), "LazyList");
You should change it to
cacheDir = new File(context.getCacheDir(), "LazyList");
I solved my problem 100% in android 2.1.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With