denzcoskun / ImageSlideshow

Android image slider.
Apache License 2.0
353 stars 141 forks source link

getPlaceholderDrawable - java.lang.OutOfMemoryError #24

Open OPunktSchmidt opened 4 years ago

OPunktSchmidt commented 4 years ago

I notice a crash on some devices. The error occurs in "getPlaceholderDrawable". I understand that there is not much you can do, if the device has too little memory, this is exactly the error. But i think the app should not crash is this case. This leads to a bad user experience and users will uninstall the app immediately.

Please think about including this part in a try catch. Or pass the exception with @throws so we can catch it in our own code

Fatal Exception: java.lang.OutOfMemoryError: Failed to allocate a 69310092 byte allocation with 4194304 free bytes and 44MB until OOM
       at dalvik.system.VMRuntime.newNonMovableArray(VMRuntime.java)
       at android.graphics.BitmapFactory.nativeDecodeAsset(BitmapFactory.java)
       at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:701)
       at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:508)
       at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1152)
       at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:930)
       at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:769)
       at android.content.res.Resources.getDrawable(Resources.java:834)
       at android.content.Context.getDrawable(Context.java:529)
       at com.squareup.picasso.RequestCreator.getPlaceholderDrawable(RequestCreator.java:741)
       at com.squareup.picasso.RequestCreator.into(RequestCreator.java:701)
       at com.squareup.picasso.RequestCreator.into(RequestCreator.java:665)
       at com.denzcoskun.imageslider.adapters.ViewPagerAdapter.instantiateItem(ViewPagerAdapter.java:57)
       at com.denzcoskun.imageslider.adapters.ViewPagerAdapter.instantiateItem(ViewPagerAdapter.java:19)
       at androidx.viewpager.widget.ViewPager.addNewItem(ViewPager.java:1010)
       at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1158)
       at androidx.viewpager.widget.ViewPager.populate(ViewPager.java:1092)
       at androidx.viewpager.widget.ViewPager.onMeasure(ViewPager.java:1622)
       at android.view.View.measure(View.java:19931)
       at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
       at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
       at android.view.View.measure(View.java:19931)
       at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:715)
       at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:461)
       at android.view.View.measure(View.java:19931)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6139)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1485)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:775)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:657)
       at android.view.View.measure(View.java:19931)
       at android.widget.ScrollView.measureChildWithMargins(ScrollView.java:1330)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
       at android.widget.ScrollView.onMeasure(ScrollView.java:352)
       at android.view.View.measure(View.java:19931)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6139)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1485)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:775)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:657)
       at android.view.View.measure(View.java:19931)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6139)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1485)
       at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:1134)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:659)
       at android.view.View.measure(View.java:19931)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6139)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
       at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:146)
       at android.view.View.measure(View.java:19931)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6139)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1485)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:775)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:657)
       at android.view.View.measure(View.java:19931)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6139)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
       at android.view.View.measure(View.java:19931)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6139)
       at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1485)
       at android.widget.LinearLayout.measureVertical(LinearLayout.java:775)
       at android.widget.LinearLayout.onMeasure(LinearLayout.java:657)
       at android.view.View.measure(View.java:19931)
       at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6139)
       at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
       at com.android.internal.policy.DecorView.onMeasure(DecorView.java:729)
       at android.view.View.measure(View.java:19931)
       at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2442)
       at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1488)
       at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1747)
       at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1372)
       at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6774)
       at android.view.Choreographer$CallbackRecord.run(Choreographer.java:926)
       at android.view.Choreographer.doCallbacks(Choreographer.java:735)
       at android.view.Choreographer.doFrame(Choreographer.java:667)
       at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:912)
       at android.os.Handler.handleCallback(Handler.java:761)
       at android.os.Handler.dispatchMessage(Handler.java:98)
       at android.os.Looper.loop(Looper.java:156)
       at android.app.ActivityThread.main(ActivityThread.java:6517)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
denzcoskun commented 4 years ago

Did you try?

android: largeHeap = "true" 

or

dexOptions{
    javaMaxHeapSize "4g"
}