Out memory error - android

Hi i have been doing a project from school and when i ran my application i have the stack trace error shown below.
03-06 14:58:02.520 11265-11265/com.example.ray.cdmsv2 E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:596)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:444)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:832)
at android.content.res.Resources.loadDrawable(Resources.java:2988)
at android.content.res.Resources.getDrawable(Resources.java:1558)
at android.graphics.drawable.StateListDrawable.inflate(StateListDrawable.java:173)
at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
at android.graphics.drawable.Drawable.createFromXml(Drawable.java:873)
at android.content.res.Resources.loadDrawable(Resources.java:2970)
at android.content.res.Resources.getDrawable(Resources.java:1558)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:323)
at android.support.v7.widget.TintManager.getDrawable(TintManager.java:147)
at android.support.design.widget.TabLayout$Tab.setIcon(TabLayout.java:1080)
at com.example.ray.cdmsv2.Activities.CreateTaskActivity.onCreate(CreateTaskActivity.java:102)
at android.app.Activity.performCreate(Activity.java:5372)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2270)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2362)
at android.app.ActivityThread.access$700(ActivityThread.java:168)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5493)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
I have looked around for solution but i still cannot resolve the issue. My application is able to run smoothly on Samsung Galaxy A3. However when i tried to run my application on a S4 and Note 4 i receive the out of memory error. I have realized that when i implement some selector in my drawable which i call in my XML files, it will cause the error, however when i remove it the error does not occur anymore. Is there any explanation for this issue? Thank you very much for helping me out

Delete the drawable and import it again using ImageAsset option.
The error is your image is too heavy for loading it into memory. Or better compress the image before copying it into the Drawable folder.

I would start by learning some best practices for memory usage by google at the dev docs #
http://developer.android.com/training/displaying-bitmaps/index.html
If you're loading large bitmaps, its quite possible the available heap memory is not enough for your bitmaps.

Your app is being choked by Android because it is using more memory than assigned, primarily due to a large image file being used as a drawable.
If it is an icon, use Android Studio's built in Image Asset generator to generate appropriate image sizes for each display type (mdpi,hdpi,xhdpi,xxhdpi and so on). If it is an image being loaded on an ImageView, you may try using the Picasso library which will handle bitmap memory on its own.

Related

Android Emulator: Unfortunately Launcher has stopped

Since the last update of my Android Studio and my SDK packages, I get this error whenever I start the emulator. Please check the screen shot below.
My logcat reports these as error statement:
06-11 05:18:22.906 15313-15328/com.android.launcher E/dalvikvm-heap﹕ Out of memory on a 88955584-byte allocation.
06-11 05:18:22.956 15313-15328/com.android.launcher E/AndroidRuntime﹕ FATAL EXCEPTION: launcher-loader
Process: com.android.launcher, PID: 15313
java.lang.OutOfMemoryError
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:587)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:422)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:840)
at android.content.res.Resources.loadDrawable(Resources.java:2115)
at android.content.res.Resources.getDrawableForDensity(Resources.java:755)
at com.android.launcher2.IconCache.getFullResIcon(IconCache.java:74)
at com.android.launcher2.IconCache.getFullResIcon(IconCache.java:113)
at com.android.launcher2.IconCache.getFullResIcon(IconCache.java:98)
at com.android.launcher2.IconCache.cacheLocked(IconCache.java:213)
at com.android.launcher2.IconCache.getTitleAndIcon(IconCache.java:155)
at com.android.launcher2.ApplicationInfo.<init>(ApplicationInfo.java:88)
at com.android.launcher2.LauncherModel$LoaderTask.loadAllAppsByBatch(LauncherModel.java:1928)
at com.android.launcher2.LauncherModel$LoaderTask.loadAndBindAllApps(LauncherModel.java:1820)
at com.android.launcher2.LauncherModel$LoaderTask.run(LauncherModel.java:1134)
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.os.HandlerThread.run(HandlerThread.java:61)
The things I have tried out:
1. Deleted the emulator and created it fresh.
2. I found some answers on StackOverFlow talking about Hardware keys. did that too.
I had the same problem
the problem was I use image on drawable that not support different
screen sizes as app icon so I changed to default icon of android studio and rebuilded the app and it now working
enter image description here

OutOfMemoryError captureSharedElementState androidL

I've been experimenting Shared elements transitions with Android-L preview (Nexus 7), and faced OutOfMemoryError exceptions when used with a ViewPager. But I also tried on Romain's google-io-2014 demo, and got the same problem after clicking on a picture then hitting back, a couple of times (between 10 to 15). Is it a bug in the SDK, and there's something that should be done on the application side (recycle())?
java.lang.OutOfMemoryError: Failed to allocate a 1817612 byte allocation with 772936 free bytes
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:810)
at android.graphics.Bitmap.createBitmap(Bitmap.java:787)
at android.graphics.Bitmap.createBitmap(Bitmap.java:754)
at android.app.ActivityTransitionCoordinator.captureSharedElementState(ActivityTransitionCoordinator.java:543)
at android.app.ActivityTransitionCoordinator.captureSharedElementState(ActivityTransitionCoordinator.java:511)
at android.app.EnterTransitionCoordinator.sendSharedElementDestination(EnterTransitionCoordinator.java:109)
at android.app.EnterTransitionCoordinator.onReceiveResult(EnterTransitionCoordinator.java:151)
at android.os.ResultReceiver$MyRunnable.run(ResultReceiver.java:43)
at android.os.Handler.handleCallback(Handler.java:738)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5070)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:836)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:631)
I/am_crash( 612): [17912,0,com.example.android.io2014,8961606,java.lang.OutOfMemoryError,Failed to allocate a 1817612 byte allocation with 772936 free bytes,VMRuntime.java,-2]
Update (10/17/2014): all fixed with SDK 21. Can't close the question.
Apparently this has been fixed in API 21 (according to the OP).
Note also that Romain Guy's sample project is just an example... he didn't bother writing code that properly scales down the images he uses (which is what you would normally do in a production application). If you are running the sample on a low-end device, it's possible that you might get out of memory errors. To avoid this, I recommend resizing and scaling down the drawable PNGs included in the project.

App force closes with java.lang.NoClassDefFoundError: android/os/AsyncTask

We recently introduced OAuth login in our app. This means using a WebView to authenticate the user, and an AsyncTask to do necessary REST calls afterwards.
Unfortunately, after introducing this login method, we're getting reports of the app force closing. This seems to be related to other AsyncTasks that are executed after the login, but the stack traces does unfortunately not tell us much:
java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:3100)
at android.view.View.performClick(View.java:3627)
at android.view.View$PerformClick.run(View.java:14329)
at android.os.Handler.handleCallback(Handler.java:605)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4511)
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:980)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at android.view.View$1.onClick(View.java:3095)
... 11 more
Caused by: java.lang.NoClassDefFoundError: android/os/AsyncTask
at com.foo.bar.TransmissionActivity.transmit(TransmissionActivity.java:44)
... 14 more
We managed to fix the error above by using RoboAsyncTask (from RoboGuice), instead of AsyncTask from the Android SDK, but we have other activities that use WebViews. WebView apparently uses AsyncTask somewhere in its call stack, and errors similar the one shown above (Caused by: java.lang.NoClassDefFoundError: android/os/AsyncTask) have started to show in our error logs.
The error happens on different devices, and different Android versions, with no apparent pattern. We have tried to reproduce the error ourselves, without any luck.
Any ideas?
It might be an issue with the build setup. (Build order of src/gen has been known to cause some issues, the libs folder for the compat library being called lib has caused some issues for me on new sdk versions).
To see if it is create a new project (in eclipse, since that's 100% android official). Add a webview and an asynctask and then do a diff on the project with your project. Ignoring src/gen/res. Hopefully you'll find that the src/gen are built in the wrong order or something like that.
~ Anders

IndexOutOfBoundsException at android.graphics.Paint.native_measureText(Native Method)

I have an android app on Google Play and occasionally get the following error reported through the developer console / ACRA. The app runs fine on my test devices and on the various AVDs that I test it on.
The stack trace doesn't state where in the app the problem is. Is there anything I can do to narrow down where to look? What generally causes the error?
java.lang.IndexOutOfBoundsException
at android.graphics.Paint.native_measureText(Native Method)
at android.graphics.Paint.measureText(Paint.java:1020)
at android.graphics.Paint.measureText(Paint.java:1057)
at android.text.Styled.drawDirectionalRun(Styled.java:267)
at android.text.Styled.measureText(Styled.java:430)
at android.text.Layout.measureText(Layout.java:1518)
at android.text.Layout.getHorizontal(Layout.java:564)
at android.text.Layout.getHorizontal(Layout.java:548)
at android.text.Layout.getPrimaryHorizontal(Layout.java:533)
at android.widget.TextView$QuickAction.getBound(TextView.java:9550)
at android.widget.TextView$QuickAction.show(TextView.java:9604)
at android.widget.TextView$QuickActionController.show(TextView.java:8846)
at android.widget.TextView.performLongClick(TextView.java:8033)
at android.view.View$CheckForLongPress.run(View.java:9096)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3701)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller
.run(ZygoteInit.java:895)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:653)
at dalvik.system.NativeStart.main(Native Method)
From the look of this, you have a race in your application initialization block. Probably one of your text resources is not fully inflated before a draw is issued. (i know, the model of the android runtime should prevent this, but if this happens when the layout is calculated, it would be plausible).
Hope this is of some help in narrowing it down.

Android FileNotFoundException res/drawable-hdpi/scrollbar_handle_vertical.9.png

The most significant user-reported crash for my app right now is below. It seems like the system cannot find the file res/drawable-hdpi/scrollbar_handle_vertical.9.png
The below example indicates the problem happens when drawing a webview, but it also happens for other activities in my app, all of which work fine most of the time.
I would think this is an android resource that I wouldn't need to worry about. But, just to test, I took the file from the sdk and placed it into my project drawable-hdpi folder for the latest release of my app. However, I still observer the crash reports in google play.
Any thoughts as to what could be happening?
I'm also not using progaurd right now, so no way that is stripping out files it shouldn't.
android.view.InflateException: Binary XML file line #26: Error inflating class com.android.internal.app.AlertController$RecycleListView
at android.view.LayoutInflater.createView(LayoutInflater.java:513)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:565)
at android.view.LayoutInflater.inflate(LayoutInflater.java:385)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
at android.webkit.WebView$InvokeListBox.run(WebView.java:8308)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:4627)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:521)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at com.android.internal.app.AlertController$RecycleListView.<init>(AlertController.java:703)
at java.lang.reflect.Constructor.constructNative(Native Method)
at java.lang.reflect.Constructor.newInstance(Constructor.java:446)
at android.view.LayoutInflater.createView(LayoutInflater.java:500)
... 14 more
Caused by: android.content.res.Resources$NotFoundException: File res/drawable-hdpi/scrollbar_handle_vertical.9.png from drawable resource ID #0x0
at android.content.res.Resources.loadDrawable(Resources.java:1714)
at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
at android.widget.AbsListView.<init>(AbsListView.java:630)
at android.widget.ListView.<init>(ListView.java:230)
at android.widget.ListView.<init>(ListView.java:226)
... 18 more
Caused by: java.io.FileNotFoundException: res/drawable-hdpi/scrollbar_handle_vertical.9.png
at android.content.res.AssetManager.openNonAssetNative(Native Method)
at android.content.res.AssetManager.openNonAsset(AssetManager.java:405)
at android.content.res.Resources.loadDrawable(Resources.java:1706)
... 22 more
It seems likely that this resource is missing on one (or more devices). i.e. the build of Android on that device is missing this file. It would be interesting to see whether the issue is affecting very specific devices.
I expect the solution will be to use a drawable in your app itself (rather than rely on one in android) and make sure your one is referenced, not the one that is missing on certain devices.
You can use tools like BugSense to track issues like this to collect data on affected devices & platform versions. This is useful if you're unable to get this information from the Google Play Store reporting.
One more case when this happens - when you use attribute/resource introduced in later android versions. There are some complex mappings attributes to indexes and when appt generates R.java it possibly can overlap some old ids and this very weird error occurs.
For me, the same error appeared when in view was set
android:foreground="?android:attr/selectableItemBackground"
selectableItemBackground was introduced in api 11, but was launched at emulator with api 7.
So check your layouts for using some resources introduced later than your minSdkVersion. It can be checked at R.java reference

Categories

Resources