0

I'm new to programming, I've been making an app for the last 3 months and learned a few things. But I haven't come across to how to solve this issue. I've been using Parse.com as my server, sending pictures, saving user data etc. With all of this data the app keeps crashing if I open some activities more than a few times, particularly activities with pictures. Now I have compressed the pictures and made them max 400x400 in resolution. But somehow the allocation is out of memory keeps popping up. Does anyone know any methods with which you can solve this? Because when the app crashes in Android Studio the previous memory which was on my phone seems to get deleted (Not all of the cache data).

Thanks.

// EDIT this is the Logcat

**

Out of memory: Heap Size=43591KB, Allocated=14395KB, Limit=49152KB
06-10 03:39:26.220    9344-9344/com.parseapp.eseen.eseen E/dalvikvm﹕ Extra info: Footprint=43591KB, Allowed Footprint=43591KB, Trimmed=21928KB
06-10 03:39:26.220    9344-9344/com.parseapp.eseen.eseen D/skia﹕ --- Unable to allocate space, reportSizeToVM = true
06-10 03:39:26.220    9344-9344/com.parseapp.eseen.eseen W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40d90390)
06-10 03:39:26.230    9344-9344/com.parseapp.eseen.eseen E/AndroidRuntime﹕ FATAL EXCEPTION: main
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.parseapp.eseen.eseen/com.parseapp.eseen.eseen.LoginActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2355)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
            at android.app.ActivityThread.access$600(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1335)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:155)
            at android.app.ActivityThread.main(ActivityThread.java:5511)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
            at android.view.LayoutInflater.createView(LayoutInflater.java:613)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:369)
            at android.app.Activity.setContentView(Activity.java:1912)
            at com.parseapp.eseen.eseen.LoginActivity.onCreate(LoginActivity.java:29)
            at android.app.Activity.performCreate(Activity.java:5066)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
            at android.app.ActivityThread.access$600(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1335)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:155)
            at android.app.ActivityThread.main(ActivityThread.java:5511)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.reflect.InvocationTargetException
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:587)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:369)
            at android.app.Activity.setContentView(Activity.java:1912)
            at com.parseapp.eseen.eseen.LoginActivity.onCreate(LoginActivity.java:29)
            at android.app.Activity.performCreate(Activity.java:5066)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
            at android.app.ActivityThread.access$600(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1335)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:155)
            at android.app.ActivityThread.main(ActivityThread.java:5511)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.OutOfMemoryError: (Heap Size=43591KB, Allocated=14395KB)
            at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
            at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:626)
            at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:473)
            at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
            at android.content.res.Resources.loadDrawable(Resources.java:1959)
            at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
            at android.view.View.<init>(View.java:3354)
            at android.view.View.<init>(View.java:3291)
            at android.view.ViewGroup.<init>(ViewGroup.java:432)
            at android.widget.RelativeLayout.<init>(RelativeLayout.java:184)
            at java.lang.reflect.Constructor.constructNative(Native Method)
            at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
            at android.view.LayoutInflater.createView(LayoutInflater.java:587)
            at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
            at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
            at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
            at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
            at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:369)
            at android.app.Activity.setContentView(Activity.java:1912)
            at com.parseapp.eseen.eseen.LoginActivity.onCreate(LoginActivity.java:29)
            at android.app.Activity.performCreate(Activity.java:5066)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1101)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2311)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2391)
            at android.app.ActivityThread.access$600(ActivityThread.java:151)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1335)
            at android.os.Handler.dispatchMessage(Handler.java:99)
            at android.os.Looper.loop(Looper.java:155)
            at android.app.ActivityThread.main(ActivityThread.java:5511)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:511)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1029)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:796)
            at dalvik.system.NativeStart.main(Native Method)

**

The code is too long to put it here since it's limited to 30,000 chars

Jawee
  • 145
  • 1
  • 1
  • 10
  • add code whatever u have tried up until now n logicat when its crashing – Ajay P. Prajapati Jun 10 '15 at 01:13
  • sorry for typo, Logcat information, and you probably getting OutOfMemory exception as far as i know, if you are trying to get Bitmap images, if i can see your code might be able to help you out. thanks – Ajay P. Prajapati Jun 10 '15 at 01:27
  • Yeah I think you got it right before even seeing the code. Give me a few mins my phone is a hassle to work with. Thanks again :) – Jawee Jun 10 '15 at 01:32
  • added answer implement it, you have lots of errors by the way, but as per your question, OutOfMemory exception will be gone and your app will work smoothly if you implement that in your app. – Ajay P. Prajapati Jun 11 '15 at 00:27
  • did you try the solution? it works or not ? please let me know – Ajay P. Prajapati Jun 11 '15 at 13:18
  • 1
    Sorry on the slow reply, wasn't home that much. I didn't try the solution yet, but when I do ill be sure to comment here. – Jawee Jun 13 '15 at 11:49
  • Finally got around to using it. Works fine, haven't been getting any crashes yet. Will keep you informed if any difficulties do occur. Thanks again! – Jawee Jun 14 '15 at 20:24
  • im damn sure it will not give you any crashes..!! n you are welcome – Ajay P. Prajapati Jun 14 '15 at 20:28

1 Answers1

1

If you are using parse.com and getting the Images from database and converting it to bitmaps it will crash your app..

what you should do is, get the image of the URL from parse.com there is method called..

 ParseFile.getUrl(); 

For that implement the Picasso library, which is perfect solution for loading images from database.

To implement picasso in your app,

compile 'com.squareup.picasso:picasso:2.5.2'

Then get the file from parse database

ParseFile file = getParseFile("ImageColumn");

To load the file

Uri url = Uri.parse(file.getUrl());

then just get context and ..add following passing your file url..

Picasso.with(context)
   .load(url)  //load from your URL of parseFile
   .into(imageView);  //set it to your ImageView

Here is the reason, why you should implement this..

Getting Bitmap file will consume so much memory, and it will give you OutOfMemory Exception, which you are getting right now. So instead you just get the URL of file and that's it. Loading image will be dependent on the Internet. so you are saving the memory by not converting every single bit into image. Also you will do in loop for every image will cause your app to crash.

ALSO full tutorial will be available from Official website Picasso Library

Ajay P. Prajapati
  • 1,973
  • 1
  • 17
  • 34