Reputation: 7114
In my app I was using a .txt file to save geopoints and strings, so instead of going through the process of deleting a bunch of newlines from a .txt I could just delete a row. So I put this in test for just saving data, saves fine, but when I load the data I get an out of memory erro for a bitmap that is 96x96 decoding a file, it just doesn't make sense to me.
This is the logcat:
03-28 09:48:30.059: E/dalvikvm-heap(4607): Out of memory on a 46096-byte allocation.
03-28 09:48:30.059: I/dalvikvm(4607): "main" prio=5 tid=1 RUNNABLE
03-28 09:48:30.059: I/dalvikvm(4607): | group="main" sCount=0 dsCount=0 obj=0x40a719a0 self=0x2a00bba8
03-28 09:48:30.059: I/dalvikvm(4607): | sysTid=4607 nice=0 sched=0/0 cgrp=apps handle=1073849308
03-28 09:48:30.070: I/dalvikvm(4607): | state=R schedstat=( 9701142608 17839341793 3050 ) utm=828 stm=142 core=0
03-28 09:48:30.070: I/dalvikvm(4607): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
03-28 09:48:30.070: I/dalvikvm(4607): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:529)
03-28 09:48:30.070: I/dalvikvm(4607): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:302)
03-28 09:48:30.070: I/dalvikvm(4607): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:328)
03-28 09:48:30.070: I/dalvikvm(4607): at com.apps.gonefishing.Information.onCreate(Information.java:80)
03-28 09:48:30.070: I/dalvikvm(4607): at android.app.Activity.performCreate(Activity.java:5104)
03-28 09:48:30.070: I/dalvikvm(4607): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-28 09:48:30.070: I/dalvikvm(4607): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-28 09:48:30.070: I/dalvikvm(4607): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-28 09:48:30.081: I/dalvikvm(4607): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-28 09:48:30.081: I/dalvikvm(4607): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-28 09:48:30.090: I/dalvikvm(4607): at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 09:48:30.090: I/dalvikvm(4607): at android.os.Looper.loop(Looper.java:137)
03-28 09:48:30.090: I/dalvikvm(4607): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-28 09:48:30.090: I/dalvikvm(4607): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 09:48:30.090: I/dalvikvm(4607): at java.lang.reflect.Method.invoke(Method.java:511)
03-28 09:48:30.090: I/dalvikvm(4607): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-28 09:48:30.090: I/dalvikvm(4607): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-28 09:48:30.090: I/dalvikvm(4607): at dalvik.system.NativeStart.main(Native Method)
03-28 09:48:30.110: D/skia(4607): --- decoder->decode returned false
03-28 09:48:30.110: D/AndroidRuntime(4607): Shutting down VM
03-28 09:48:30.110: W/dalvikvm(4607): threadid=1: thread exiting with uncaught exception (group=0x40a70930)
03-28 09:48:30.140: E/AndroidRuntime(4607): FATAL EXCEPTION: main
03-28 09:48:30.140: E/AndroidRuntime(4607): java.lang.OutOfMemoryError
03-28 09:48:30.140: E/AndroidRuntime(4607): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
03-28 09:48:30.140: E/AndroidRuntime(4607): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:529)
03-28 09:48:30.140: E/AndroidRuntime(4607): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:302)
03-28 09:48:30.140: E/AndroidRuntime(4607): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:328)
03-28 09:48:30.140: E/AndroidRuntime(4607): at com.apps.gonefishing.Information.onCreate(Information.java:80)
03-28 09:48:30.140: E/AndroidRuntime(4607): at android.app.Activity.performCreate(Activity.java:5104)
03-28 09:48:30.140: E/AndroidRuntime(4607): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
03-28 09:48:30.140: E/AndroidRuntime(4607): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
03-28 09:48:30.140: E/AndroidRuntime(4607): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
03-28 09:48:30.140: E/AndroidRuntime(4607): at android.app.ActivityThread.access$600(ActivityThread.java:141)
03-28 09:48:30.140: E/AndroidRuntime(4607): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
03-28 09:48:30.140: E/AndroidRuntime(4607): at android.os.Handler.dispatchMessage(Handler.java:99)
03-28 09:48:30.140: E/AndroidRuntime(4607): at android.os.Looper.loop(Looper.java:137)
03-28 09:48:30.140: E/AndroidRuntime(4607): at android.app.ActivityThread.main(ActivityThread.java:5039)
03-28 09:48:30.140: E/AndroidRuntime(4607): at java.lang.reflect.Method.invokeNative(Native Method)
03-28 09:48:30.140: E/AndroidRuntime(4607): at java.lang.reflect.Method.invoke(Method.java:511)
03-28 09:48:30.140: E/AndroidRuntime(4607): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
03-28 09:48:30.140: E/AndroidRuntime(4607): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
03-28 09:48:30.140: E/AndroidRuntime(4607): at dalvik.system.NativeStart.main(Native Method)
One thing I noticed is that every time the heap message comes up, there is only 5 to 6 percent available, so I started the emulator wiping the data and it's the same thing. This is an api 17 emulator, when the app was run with the text file it ran perfectly.
The next thing I'm going to try is; even when I open the database to read I'm using:
db = dbHelper.getWritableDatabase();
So I'm going to change it to getReadableDatabase
It's not that much of a change and in the activity that is before this one with the error, it finishes and everything. There are 2 bitmaps sent back and forth to eachother one on a canvas in a TextWatcher. I think it just takes memory of 2 bitmaps 320X480 ran fine with the .txt file.
Any advice is greatly appreciated, thank you for your time.
Cursor cursor;
db.read();
cursor = db.getAllEntries();
boolean go = cursor.moveToFirst();
while(cursor.isAfterLast() != true){
Drawable imagebig = null;
Bitmap photobig = null;
int lat = cursor.getInt(MyDBAdapter.LATITUDE_COLUMN);
int lng = cursor.getInt(MyDBAdapter.LONGITUDE_COLUMN);
GeoPoint recall = new GeoPoint(lat,lng);
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Gone");
file = new File(file.getPath(),"Thumbs");
String string = cursor.getString(MyDBAdapter.FILE_COLUMN);
File file1 = new File(file.getPath() + File.separator + "thumb" + string);
Uri uri = Uri.fromFile(file1);
if(file1.exists()){
//photobig = BitmapFactory.decodeFile(file1.getAbsolutePath());
uri = Uri.fromFile(file1);
try {
photobig = MediaStore.Images.Media.getBitmap(getContentResolver(), uri);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
db.close();
cursor.close();
Upvotes: 0
Views: 266
Reputation: 6260
And change this
while(cursor.isAfterLast() != true){
for that
while(!cursor.isAfterLast()){
it hurts. *Don't take it in a bad way :)
Upvotes: 0
Reputation: 3571
You have an infinite while loop. The cursor needs to be advanced.
Add cursor.moveToNext(); to your while loop.
Upvotes: 3