I have a ViewPager which displays the details of a news entry. You can swipe between the 30 entries back and forth. Each of these entries is a View which holds a ImageView. This ImageView is filled with an image from an URL using Picasso Image Library.
It works fine, but sometimes when I swipe through almost all of the various items (fragments) my app suddenly crashes, getting this error:
Caused by: java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
at android.content.res.Resources.loadDrawable(Resources.java:2208)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.ImageView.<init>(ImageView.java:129)
at android.widget.ImageView.<init>(ImageView.java:119)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:594)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at com.app.mobil.fragment.placeholder.FanpicPlaceholderFragment.onCreateView(FanpicPlaceholderFragment.java:92)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1504)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:942)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1121)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1484)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:482)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1073)
at android.support.v4.view.ViewPager.populate(ViewPager.java:919)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:249)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
at android.view.Choreographer.doCallbacks(Choreographer.java:574)
at android.view.Choreographer.doFrame(Choreographer.java:543)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5139)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612)
at dalvik.system.NativeStart.main(Native Method)
And during swiping I sometimes get following Logcat message (when the current View contains large images loaded into the ImageView):
09-25 13:19:59.816 31859-32208/com.app.mobile E/dalvikvm-heap﹕ Out of memory on a 3276816-byte allocation.
I have one concern about the whole thing: The images I load with Picasso into the ImageViews is sometimes quite large (~ 3MB per image).
Can somebody explain to me what I am doing wrong?
try this:
android:largeHeap="true"
in your manifest , in application tag
Transform images into layouts to reduce memory size using following code -
Picasso.with(context).load(url).resize(width, height).into(imageView)
Make sure that you are using Picasso library with version - 2.3.4
Related
E/UncaughtException: android.view.InflateException: Binary XML file line #0: Error inflating class TextView
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at in.saneswap.fragment.SwipeWithBuddiesFragment.onCreateView(SourceFile:93)
at android.support.v4.app.Fragment.performCreateView(SourceFile:2354)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1419)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(SourceFile:1740)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1809)
at android.support.v4.app.BackStackRecord.executeOps(SourceFile:799)
at android.support.v4.app.FragmentManagerImpl.executeOps(SourceFile:2580)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(SourceFile:2367)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(SourceFile:2322)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:2229)
at android.support.v4.app.FragmentManagerImpl$1.run(SourceFile:700)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/line.xml from drawable resource ID #0x7f0801d7
at android.content.res.Resources.loadDrawable(Resources.java:2096)
at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
at android.widget.TextView.<init>(TextView.java:806)
at android.support.v7.widget.AppCompatTextView.<init>(SourceFile:75)
at android.support.v7.widget.AppCompatTextView.<init>(SourceFile:71)
at android.support.v7.app.AppCompatViewInflater.createView(SourceFile:103)
at android.support.v7.app.AppCompatDelegateImplV9.createView(SourceFile:1024)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(SourceFile:1081)
at android.view.LayoutInflater$FactoryMerger.onCreateView(LayoutInflater.java:172)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:684)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at in.saneswap.fragment.SwipeWithBuddiesFragment.onCreateView(SourceFile:93)
at android.support.v4.app.Fragment.performCreateView(SourceFile:2354)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1419)
at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(SourceFile:1740)
at android.support.v4.app.FragmentManagerImpl.moveToState(SourceFile:1809)
at android.support.v4.app.BackStackRecord.executeOps(SourceFile:799)
at android.support.v4.app.FragmentManagerImpl.executeOps(SourceFile:2580)
at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(SourceFile:2367)
at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(SourceFile:2322)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(SourceFile:2229)
at android.support.v4.app.FragmentManagerImpl$1.run(SourceFile:700)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #0: invalid drawable tag vector
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:933)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
From the documentation:
Android 4.4 (API level 20) and lower doesn't support vector drawables. If your minimum API level is set at one of these API levels, you have two options when using Vector Asset Studio: generate Portable Network Graphic (PNG) files (the default) or use the Support Library.
You need to check if you are using some functionality that cannot be backported, otherwise use the support library.
So I have this one app in the Play Store with few thausands of downloads and I guess some of them are happy users as well. App is strongly based on Google Maps V2. Everything works fine except I've noticed few exceptions with affected 4 users in total (in last 30 days). There seems to be some kind of issue with inflating the Google Map but I cannot get any info from the log itself.
Here is my crashlytics full log for those users:
Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.*packageid*/com.*packageid*.views.map.MapActivity}: android.view.InflateException: Binary XML file line #16: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2187)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)
at android.app.ActivityThread.access$800(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by android.view.InflateException: Binary XML file line #16: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:745)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136)
at com.parkanizer.parkingapp.views.map.MapActivity.onCreate(MapActivity.java:106)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)
at android.app.ActivityThread.access$800(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(NativeStart.java)
Caused by java.lang.NullPointerException
at maps.G.a.a(Unknown Source)
at maps.V.N.a(Unknown Source)
at maps.D.e.a(Unknown Source)
at maps.D.p.a(Unknown Source)
at maps.ad.ae.a(Unknown Source)
at maps.ad.t.a(Unknown Source)
at maps.ad.M.a(Unknown Source:2000)
at uy.onTransact(:com.google.android.gms.DynamiteModulesB:107)
at android.os.Binder.transact(Binder.java:361)
at com.google.android.gms.maps.internal.IMapFragmentDelegate$zza$zza.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment$zza.onCreateView(Unknown Source)
at com.google.android.gms.dynamic.zza$4.zzb(Unknown Source)
at com.google.android.gms.dynamic.zza.zza(Unknown Source)
at com.google.android.gms.dynamic.zza.onCreateView(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source)
at com.parkanizer.parkingapp.views.MySupportMapFragment.onCreateView(MySupportMapFragment.java:18)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1974)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1036)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1230)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1332)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2288)
at android.support.v4.app.FragmentController.onCreateView(FragmentController.java:120)
at android.support.v4.app.FragmentActivity.dispatchFragmentsOnCreateView(FragmentActivity.java:357)
at android.support.v4.app.BaseFragmentActivityHoneycomb.onCreateView(BaseFragmentActivityHoneycomb.java:31)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:80)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
at android.view.LayoutInflater.parseInclude(LayoutInflater.java:839)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:745)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:276)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:136)
at com.parkanizer.parkingapp.views.map.MapActivity.onCreate(MapActivity.java:106)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2151)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2236)
at android.app.ActivityThread.access$800(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1199)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5102)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
Here is my XML file for the view. There is really nothing special going on, and for most of the cases users are crash-free.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<RelativeLayout
android:id="#+id/content_map"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/map"
tools:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"
map:cameraTargetLat="50.2633971"
map:cameraTargetLng="19.0111041"
map:cameraZoom="10"
class="com.google.android.gms.maps.SupportMapFragment" />
<... Some other typical UI elements ...>
I wans't able to fix my problem, also to reproduce it. Do you have any ideas?
In fabric, there is total of 33 crashes with affected 4 users. 88% of the crashes is for strange kind of device "Lechpol", the rest is samsung (GT-I9300)
All of them running on Android 4.4.
Do you guys have any idea what could cause the crash? Any advices appreciated.
EDIT: after further research I found the device that has so many crashes, this is it:
https://www.ox.ee/en/product/836741
set visibility gone/visible for relative layout
<RelativeLayout
android:id="#+id/content_map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:visibility="gone" >
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map"
tools:context=".MapsActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
<activity android:name="com.bison.activities.YourActivity"
android:hardwareAccelerated="true"
>
<intent-filter>
<action
android:name="android.intent.action.VIEW" />
</intent-filter>
</activity>
Try adding this to you activity in manifest. If it helps study the hardware acceleration in google documentation
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
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
Okay, so in my app I have multiple ImageViews each holding an .png icon. right now there are 7... And yet my app, at random intervals, will crash with a anr dialog (App Not Responding) and it then throws this exception:
10-08 00:14:15.528 32732-32732/com.antechdevelopment.NotificationReminders E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.antechdevelopment.NotificationReminders, PID: 32732
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:677)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:507)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:872)
at android.content.res.Resources.loadDrawable(Resources.java:3024)
at android.content.res.Resources.getDrawable(Resources.java:1586)
at android.app.ApplicationPackageManager.getDefaultActivityIcon(ApplicationPackageManager.java:783)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:3466)
at com.android.internal.policy.impl.PhoneWindow.getDecorView(PhoneWindow.java:1879)
at android.view.Window.findViewById(Window.java:924)
at android.app.Activity.findViewById(Activity.java:1965)
at android.app.Activity$1.findViewById(Activity.java:745)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:880)
at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1062)
at android.app.BackStackRecord.run(BackStackRecord.java:684)
at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1447)
at android.app.Activity.performStart(Activity.java:5435)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2278)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
at android.app.ActivityThread.access$900(ActivityThread.java:161)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5356)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Does anyone have an idea? I'm pretty stumped and annoyed! Thanks!
Just as the error states, you're running out of memory. This is most likely due to the size of the image and how its being loaded. A lot of libs have been created to solve these issues.
Try using some image loading libraries like one of the ones below. Most likely you'll be able to solve your issue using one of these battle tested libs.
Picasso
Ion
Universal Image Loader
I have a problem trying to create a subclass of LinearLayout. I have a simple fragment with this layout
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/map_container"
>
<!-- Map view -->
<org.osmdroid.views.MapView
android:id="#+id/fragment_map_map_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"/>
<!-- Record description -->
<com.example.SmallRecordDetailsWidget
android:id="#+id/fragment_map_record_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</FrameLayout>
The SmallRecordDetailsWidget is a subclass of LinearLayout.
My problem is that I can't find the right way to instantiate/inflate it.
Here's what my SmallRecordDetailsWidget looks like now
public class SmallRecordDetailsWidget extends LinearLayout {
private final int layoutID = R.layout.small_record_details;
public SmallRecordDetailsWidget(Context context, AttributeSet attrs) {
super(context, attrs);
LayoutInflater.from(context).inflate(this.layoutID, this, true) ;
}
}
Then in fragment's onCreateView I'm doing:
#Override
public View onCreateView(
LayoutInflater inflater, ViewGroup containter, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_map, containter, false) ;
this.mapView = (MapView)( view.findViewById(R.id.fragment_map_map_view) );
this.recordDetailsWidget = (SmallRecordDetailsWidget)( view.findViewById(R.id.fragment_map_record_detail) ) ;
return view;
}
But this codes brakes on View view = inflater.inflate(...) with
android.view.InflateException: Binary XML file line #18: Error inflating class com.lexues.android.hari_prototype.views.SmallRecordDetailsWidget
which I can track to being thrown on
LayoutInflater.from(context).inflate(this.layoutID, this, true) ;
line from SmallRecordDetailsWidget's constructor. Inflater fails even on dead simple layout, like this one
<?xml version="1.0" encoding="utf-8"?>
<!-- A widget with details of selected point of interest. This will be placed at the bottom of the map widget -->
<com.lexues.android.hari_prototype.views.SmallRecordDetailsWidget xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/small_record_details_layout"
android:layout_width="match_parent"
android:layout_height="82dp">
</com.lexues.android.hari_prototype.views.SmallRecordDetailsWidget>
Now, I've stripped my problem to smallest case that reproduces the issue, so it looks like I'm not doing anything useful here, but the goal is for SmallRecordDetailsWidget to have a few simple member widgets and then do a bit of work with them. If I understand correctly as long as they would be defined within layout file that SmallRecordDetailsWidget's constructor inflates (as children of the root element) then they should also get inflated, so that I can later on get hold of them with findViewById(...).
Edit - added stack trace and a bit of extra details
The stack trace is:
09-01 09:24:18.661 6330-6330/com.lexues.android.hari_prototype E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.lexues.android.hari_prototype, PID: 6330
android.view.InflateException: Binary XML file line #18: Error inflating class com.lexues.android.hari_prototype.views.SmallRecordDetailsWidget
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at com.lexues.android.hari_prototype.controllers.fragments.MapFragment.onCreateView(MapFragment.java:87)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:478)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
at android.view.View.measure(View.java:17396)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5365)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:17396)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5365)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:382)
at android.view.View.measure(View.java:17396)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5365)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2505)
at android.view.View.measure(View.java:17396)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2175)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1316)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1513)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1200)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6401)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:573)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
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:423)
at android.view.LayoutInflater.createView(LayoutInflater.java:600)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:761)
at android.view.LayoutInflater.inflate(LayoutInflater.java:498)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at com.lexues.android.hari_prototype.controllers.fragments.MapFragment.onCreateView(MapFragment.java:87)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1500)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:938)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1115)
at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1478)
at android.support.v4.app.FragmentManagerImpl.executePendingTransactions(FragmentManager.java:478)
at android.support.v4.app.FragmentPagerAdapter.finishUpdate(FragmentPagerAdapter.java:141)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1068)
at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1436)
at android.view.View.measure(View.java:17396)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5365)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at android.view.View.measure(View.java:17396)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5365)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:382)
at android.view.View.measure(View.java:17396)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5365)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2505)
at android.view.View.measure(View.java:17396)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2175)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1316)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1513)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1200)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6401)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:803)
at android.view.Choreographer.doCallbacks(Choreographer.java:603)
at android.view.Choreographer.doFrame(Choreographer.java:573)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:789)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:157)
at android.app.ActivityThread.main(ActivityThread.java:5335)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #5: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:626)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702)
at android.view.LayoutInflater.inflate(LayoutInflater.java:470)
at android.view.LayoutInflater.inflate(LayoutInflater.java:398)
at com.lexues.android.hari_prototype.views.SmallRecor
09-01 09:24:19.381 882-6350/? E/android.os.Debug﹕ !#Dumpstate > sdumpstate -k -t -z -d -o /data/log/dumpstate_app_error
09-01 09:24:20.361 267-267/? E/SMD﹕ DCD ON
As noted in the code I posted, in the constructor of SmallRecordDetailsWidget I inflate layout R.layout.small_record_details, where small_record_details.xml is the xml that defines the widget (while com.lexues.android.hari_prototype.views.SmallRecordDetailsWidget is the name of its root tag).
And just to make my goals clear - I want to create a widget that contains a few others. I hope to define all of them in the xml for that 'compound widget', then in costructor get references to child widgets, so that client can do things like SmallRecordDetailsWidget.titleTextWidget.setText(...), etc.
Reading your question it seems your are inflating the wrong layout in SmallRecordDetailsWidget's constructor.
There, you should NOT use the tag
<com.lexues.android.hari_prototype.views.SmallRecordDetailsWidget>
You use that tag when you are inflating/instatiating the custom layout from your fragment, but NOT when you are inflating a small view hierarchy and attach it to your custom layout. The view hierarchy should not contain that tag, try putting something like a TextView in layout/small_record_details.xml
So after more digging with better keyword (googling for custom View instead of extending ViewGroup), this article helped me:
http://www.tiemenschut.com/how-to-create-compound-controls-for-android/
My problem was that I used com.lexues.android.hari_prototype.views.SmallRecordDetailsWidget as the name of the root element of the layout which defined my custom widget. I should had simply used LinearLayout or any other layout as desired. Which makes sense come to think of it, otherwise I'm referencing the element before finishing defining it. Silly me.