I am using android 4.0.4, kernel 3.0.8 +
Each so often, BitmapFactory.decodeFile returns a null bitmap.
Please note that if the factory bitmap does not load the bitmap, I will immediately try again, up to 4 times, and this often works (!)
There are many people who complain about this. Most questions have answers related to the placement of the bitmap, or to the nature of the stream of the discarded input stream / http / independently. I solved it - in fact, I reduced my problem to an android application of such ridiculous simplicity that it could be called a test case.
My application has one action, which contains one button, which, when pressed, launches a stream that goes through the directory of external files, trying to load everything into it in bitmap images. I do not use a bitmap, or hold it, or something else, I just load and forget:
public class MainActivity extends Activity { private static final String TAG = "bmpbash"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } @Override public boolean onCreateOptionsMenu(Menu menu) {
I will see the output as follows:
10-22 17:27:57.688: W/bmpbash(1131): translucent.png[0] - OK 10-22 17:27:57.698: W/bmpbash(1131): fearthecow.png[0] - OK 10-22 17:27:57.798: W/bmpbash(1131): gui2.png[0] - OK 10-22 17:27:57.888: W/bmpbash(1131): gui.png[0] - OK 10-22 17:27:58.058: W/bmpbash(1131): boot.png[0] - OK 10-22 17:27:58.218: E/bmpbash(1131): trainer2.png[0] - NULL bitmap 10-22 17:27:58.378: W/bmpbash(1131): trainer2.png[1] - OK
In the above code, you will see a commented out alternative loading sequence in which, instead of using decodeFile, I load the file in bytes [], and then use decodeByteArray. This has the same effect (decodeByteArray fails, and then immediately gets exactly in one byte array!), But I note that errors are much less common.
In the case of decodeFile, possibly 1 out of 10 attempts returns null. In the case of decodeByteArray, perhaps only 1 out of 100. Not always the same file fails, but some files seem to fail more often than others.
My best guess is that the png decoder is crashing, which is most likely to happen if it works for a longer period of time, but after that I am a bit lost. If anyone has any light to get rid of the problem or alternative approaches to downloading png files, I would really appreciate it!