udacity / AdvancedAndroid_TeaTime

115 stars 307 forks source link

com.example.android.teatime E/art: Throwing OutOfMemoryError #3

Open acrozes opened 7 years ago

acrozes commented 7 years ago

Testing the first exercice on my Samsung S4, I have an out of memory error. Is exist a way to increase the memory limit ?

The stack: 06-03 01:47:04.002 27206-27206/com.example.android.teatime E/art: Throwing OutOfMemoryError "Failed to allocate a 23040012 byte allocation with 1913468 free bytes and 1868KB until OOM" 06-03 01:47:04.002 27206-27206/com.example.android.teatime E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.android.teatime, PID: 27206 java.lang.OutOfMemoryError: Failed to allocate a 23040012 byte allocation with 1913468 free bytes and 1868KB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:726) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:547) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1014) at android.content.res.Resources.loadDrawableForCookie(Resources.java:3730) at android.content.res.Resources.loadDrawable(Resources.java:3603) at android.content.res.Resources.getDrawable(Resources.java:1852) at android.content.Context.getDrawable(Context.java:408) at android.support.v4.content.ContextCompatApi21.getDrawable(ContextCompatApi21.java:30) at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:372) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:202) at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:190) at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100) at android.support.v7.widget.AppCompatImageHelper.setImageResource(AppCompatImageHelper.java:73) at android.support.v7.widget.AppCompatImageView.setImageResource(AppCompatImageView.java:81) at com.example.android.teatime.TeaMenuAdapter.getView(TeaMenuAdapter.java:75) at android.widget.AbsListView.obtainView(AbsListView.java:2823) at android.widget.GridView.makeAndAddView(GridView.java:1437) at android.widget.GridView.makeRow(GridView.java:361) at android.widget.GridView.fillDown(GridView.java:302) at android.widget.GridView.fillFromTop(GridView.java:437) at android.widget.GridView.layoutChildren(GridView.java:1302) at android.widget.AbsListView.onLayout(AbsListView.java:2627) at android.view.View.layout(View.java:16711) at android.view.ViewGroup.layout(ViewGroup.java:5328) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1077) at android.view.View.layout(View.java:16711) at android.view.ViewGroup.layout(ViewGroup.java:5328) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573) at android.widget.FrameLayout.onLayout(FrameLayout.java:508) at android.view.View.layout(View.java:16711) at android.view.ViewGroup.layout(ViewGroup.java:5328) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1702) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1556) at android.widget.LinearLayout.onLayout(LinearLayout.java:1465) at android.view.View.layout(View.java:16711) at android.view.ViewGroup.layout(ViewGroup.java:5328) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573) at android.widget.FrameLayout.onLayout(FrameLayout.java:508) at android.view.View.layout(View.java:16711) at android.view.ViewGroup.layout(ViewGroup.java:5328) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1702) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1556) at android.widget.LinearLayout.onLayout(LinearLayout.java:1465) at android.view.View.layout(View.java:16711) at android.view.ViewGroup.layout(ViewGroup.java:5328) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:573) at android.widget.FrameLayout.onLayout(FrameLayout.java:508) at android.view.View.layout(View.java:16711) at android.view.ViewGroup.layout(ViewGroup.java:5328) at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2319) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2032) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1191) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6642) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:777) at android.view.Choreographer.doCallbacks(Choreographer.java:590) at android.view.Choreographer.doFrame(Choreographer.java:560)

ToanNV commented 7 years ago

This bug happens on my cell phone Samsung Galaxy J7 prime, too when I use the source code on the branches develop_branch and TESP.00-StartingCode. But it does not on the emulator.

emmjk commented 7 years ago

I also use Galaxy s5 , still the same error comes .

francescosalamone commented 6 years ago

I have the same problem with my LG G4

Mahmoood commented 6 years ago

This is because the images are located inside the drawable folder, so it will be resized according to the current device density.

To fix that move the images (tea images) to a new folder named drawable-nodpi instead of locating them inside drawable folder, in this case, the images will be loaded with the same original size without resizing them to go along with device density.

ern1001 commented 6 years ago

Mahmoood's solution fixed the problem for me. I had the "Out of memory" problem on 2 phones and on 2 AVD emulated devices that I tried. Now it finally runs ok on all of them by using Mahmoood;s fix.

nindyahapsari commented 5 years ago

@Mahmoood thank you. Your solution fixes my problem.