I am developing an application that deals with storing lot of images in cache, I frequently encounter error like - out of memory. Can anyone suggest a way to deal with this issue
Error Log
Report of logcat :
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): FATAL EXCEPTION: main
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:450)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:326)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.content.res.Resources.loadDrawable(Resources.java:1709)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.content.res.Resources.getDrawable(Resources.java:581)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.view.View.setBackgroundResource(View.java:7533)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at com.lht.icruise.activity.shipdetails.ShipDetailsActivity.onCreate(ShipDetailsActivity.java:99)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1586)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1638)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:928)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.os.Handler.dispatchMessage(Handler.java:99)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.os.Looper.loop(Looper.java:123)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at android.app.ActivityThread.main(ActivityThread.java:3647)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at java.lang.reflect.Method.invokeNative(Native Method)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at java.lang.reflect.Method.invoke(Method.java:507)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
06-27 19:41:16.425: ERROR/AndroidRuntime(13965): at dalvik.system.NativeStart.main(Native Method)
If you using large bitmaps, recycling the bitmaps to free up memory using recycle() method on bitmap when that bitmap no more used, might help you.
Check if this answer helps you: Strange out of memory issue while loading an image to a Bitmap object
Related
I'm trying to start a new Activity, android. this is creating following error.
Note: i have updated the new activity in manifest
Logcat
06-27 18:00:39.543: D/AndroidRuntime(908): Shutting down VM
06-27 18:00:39.543: W/dalvikvm(908): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
06-27 18:00:39.563: E/AndroidRuntime(908): FATAL EXCEPTION: main
06-27 18:00:39.563: E/AndroidRuntime(908): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.dipl.smpm.smpm/com.dipl.smpm.smpm.UpdateTask}: android.view.InflateException: Binary XML file line #15: Error inflating class button
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2663)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.os.Handler.dispatchMessage(Handler.java:99)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.os.Looper.loop(Looper.java:123)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-27 18:00:39.563: E/AndroidRuntime(908): at java.lang.reflect.Method.invokeNative(Native Method)
06-27 18:00:39.563: E/AndroidRuntime(908): at java.lang.reflect.Method.invoke(Method.java:521)
06-27 18:00:39.563: E/AndroidRuntime(908): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-27 18:00:39.563: E/AndroidRuntime(908): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-27 18:00:39.563: E/AndroidRuntime(908): at dalvik.system.NativeStart.main(Native Method)
06-27 18:00:39.563: E/AndroidRuntime(908): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class button
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:576)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
06-27 18:00:39.563: E/AndroidRuntime(908): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:198)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.Activity.setContentView(Activity.java:1647)
06-27 18:00:39.563: E/AndroidRuntime(908): at com.dipl.smpm.smpm.UpdateTask.onCreate(UpdateTask.java:11)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-27 18:00:39.563: E/AndroidRuntime(908): ... 11 more
06-27 18:00:39.563: E/AndroidRuntime(908): Caused by: java.lang.ClassNotFoundException: android.view.button in loader dalvik.system.PathClassLoader[/data/app/com.dipl.smpm.smpm-2.apk]
06-27 18:00:39.563: E/AndroidRuntime(908): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
06-27 18:00:39.563: E/AndroidRuntime(908): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
06-27 18:00:39.563: E/AndroidRuntime(908): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.createView(LayoutInflater.java:466)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.onCreateView(LayoutInflater.java:544)
06-27 18:00:39.563: E/AndroidRuntime(908): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:66)
06-27 18:00:39.563: E/AndroidRuntime(908): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:563)
It seems that You have defined Your Button inside the xml layout as
<button
android:layout_width="fill_parent"
..........
/>
but You have to write a capital b
<Button
android:layout_width="fill_parent"
............
/>
This is what the line says inside Error Message
Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class button <--- You wrote button, but it has to be Button
I have an activity where there are 2 spinners. I fill the spinners with lists taken from an xml file like this one :
<outil id="1" name="Décompacteur">
<travail id="1">Travail au sol</travail>
<travail id="1001">Autre</travail>
</outil>
<outil id="2" name="Cultivateur">
<travail id="3">Travail au sol</travail>
<travail id="1002">Autre</travail>
</outil>
In another activity, I can change the file from which I build the lists.
My problem is : I select a tool (outil) at the end of a long list of tools, for example position = 6. Then I change the file, and the tool list now has only 4 items. I set a new adapter :
listNameOutil = getOutilNameList(listOutilObject);
adapterOutil = new ArrayAdapter<String>(this, R.layout.spinners_base, listNameOutil);
adapterOutil.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner_outil.setAdapter(adapterOutil);
But I still get an error, and I don't know where it comes from provided there is no "caused by" in the stack trace... Please note that I also do a spinner_outil.setSelection(positionSaved);. At first, I was trying to catch the exception on this line but it seems that it's not this line which is the problem.
Any ideas to solve this?
Here is the Stack trace :
06-27 14:46:01.811: W/dalvikvm(20824): threadid=1: thread exiting with uncaught exception (group=0x40d0c930)
06-27 14:46:01.821: E/AndroidRuntime(20824): FATAL EXCEPTION: main
06-27 14:46:01.821: E/AndroidRuntime(20824): java.lang.IndexOutOfBoundsException: Invalid index 6, size is 4
06-27 14:46:01.821: E/AndroidRuntime(20824): at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
06-27 14:46:01.821: E/AndroidRuntime(20824): at java.util.ArrayList.get(ArrayList.java:304)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.ArrayAdapter.getItem(ArrayAdapter.java:337)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:390)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.ArrayAdapter.getView(ArrayAdapter.java:362)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.Spinner.makeAndAddView(Spinner.java:546)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.Spinner.layout(Spinner.java:495)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.Spinner.onLayout(Spinner.java:459)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.View.layout(View.java:14008)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1021)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.View.layout(View.java:14008)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.View.layout(View.java:14008)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.View.layout(View.java:14008)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.View.layout(View.java:14008)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewGroup.layout(ViewGroup.java:4373)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.Choreographer.doCallbacks(Choreographer.java:562)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.Choreographer.doFrame(Choreographer.java:532)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.os.Handler.handleCallback(Handler.java:725)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.os.Handler.dispatchMessage(Handler.java:92)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.os.Looper.loop(Looper.java:137)
06-27 14:46:01.821: E/AndroidRuntime(20824): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-27 14:46:01.821: E/AndroidRuntime(20824): at java.lang.reflect.Method.invokeNative(Native Method)
06-27 14:46:01.821: E/AndroidRuntime(20824): at java.lang.reflect.Method.invoke(Method.java:511)
06-27 14:46:01.821: E/AndroidRuntime(20824): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-27 14:46:01.821: E/AndroidRuntime(20824): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-27 14:46:01.821: E/AndroidRuntime(20824): at dalvik.system.NativeStart.main(Native Method)
EDIT :
In the on Start, I bind to my service. Then, in onServiceConnected, I ask the service for configuration informations :
try {
remoteServiceMain.requeteLireConfig();
} catch (RemoteException e) {
e.printStackTrace();
}
Then, still in the onServiceConnected, I define the layout :
spinner_outil = (Spinner) findViewById(R.id.spinner_outil_layout);
spinner_outil.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long arg3) {
}
}
Then onServiceConnected is finished. Please note that I get the last log before error there.
REDDIT :
I do setSelection(positionSaved); after spinner_outil.setAdapter(adapterOutil);, and I set positionSaved when I get the answer from the service after calling :
try {
remoteServiceMain.requeteLireConfig();
} catch (RemoteException e) {
e.printStackTrace();
}
positionSaved is sent by the Service, which takes it from a Configuration File. positionSaved is saved evrytime the user clicks on an Item of the spinner. The reason why I get it from the service and not directly from the File is that I use the same method for other things
I have an app that deals with images, it works fine with some devices ex. HTC ONE X, and others dont ex. GALAXY NOTE, the list is big IDK the problem exatcly cuz it works in some, and it dont in others. also it doesnt work on the emulator the default one but a small one it does work
this is the logcat I get
08-15 18:30:39.070: I/dalvikvm-heap(334): Clamp target GC heap from 25.723MB to 24.000MB
08-15 18:30:39.090: D/dalvikvm(334): GC_FOR_MALLOC freed <1K, 51% free 2672K/5379K, external 19015K/19657K, paused 38ms
08-15 18:30:39.370: D/dalvikvm(334): GC_EXTERNAL_ALLOC freed <1K, 51% free 2672K/5379K, external 19015K/19657K, paused 45ms
08-15 18:30:39.400: E/dalvikvm-heap(334): 810000-byte external allocation too large for this process.
08-15 18:30:39.510: I/dalvikvm-heap(334): Clamp target GC heap from 25.724MB to 24.000MB
08-15 18:30:39.510: E/GraphicsJNI(334): VM won't let us allocate 810000 bytes
08-15 18:30:39.510: D/dalvikvm(334): GC_FOR_MALLOC freed 0K, 51% free 2672K/5379K, external 19015K/19657K, paused 36ms
08-15 18:30:39.532: D/AndroidRuntime(334): Shutting down VM
08-15 18:30:39.532: W/dalvikvm(334): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-15 18:30:39.600: E/AndroidRuntime(334): FATAL EXCEPTION: main
08-15 18:30:39.600: E/AndroidRuntime(334): java.lang.RuntimeException: Unable to start activity ComponentInfo{app.com.android.editor/app.com.android.editor.Option}: android.view.InflateException: Binary XML file line #317: Error inflating class <unknown>
08-15 18:30:39.600: E/AndroidRuntime(334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.os.Handler.dispatchMessage(Handler.java:99)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.os.Looper.loop(Looper.java:123)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-15 18:30:39.600: E/AndroidRuntime(334): at java.lang.reflect.Method.invokeNative(Native Method)
08-15 18:30:39.600: E/AndroidRuntime(334): at java.lang.reflect.Method.invoke(Method.java:507)
08-15 18:30:39.600: E/AndroidRuntime(334): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-15 18:30:39.600: E/AndroidRuntime(334): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-15 18:30:39.600: E/AndroidRuntime(334): at dalvik.system.NativeStart.main(Native Method)
08-15 18:30:39.600: E/AndroidRuntime(334): Caused by: android.view.InflateException: Binary XML file line #317: Error inflating class <unknown>
08-15 18:30:39.600: E/AndroidRuntime(334): at android.view.LayoutInflater.createView(LayoutInflater.java:518)
08-15 18:30:39.600: E/AndroidRuntime(334): at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.view.LayoutInflater.rInflate(LayoutInflater.java:623)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.view.LayoutInflater.rInflate(LayoutInflater.java:626)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.view.LayoutInflater.inflate(LayoutInflater.java:408)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
08-15 18:30:39.600: E/AndroidRuntime(334): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.app.Activity.setContentView(Activity.java:1657)
08-15 18:30:39.600: E/AndroidRuntime(334): at app.com.android.editor.Option.onCreate(Option.java:40)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
08-15 18:30:39.600: E/AndroidRuntime(334): ... 11 more
08-15 18:30:39.600: E/AndroidRuntime(334): Caused by: java.lang.reflect.InvocationTargetException
08-15 18:30:39.600: E/AndroidRuntime(334): at java.lang.reflect.Constructor.constructNative(Native Method)
08-15 18:30:39.600: E/AndroidRuntime(334): at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.view.LayoutInflater.createView(LayoutInflater.java:505)
08-15 18:30:39.600: E/AndroidRuntime(334): ... 25 more
08-15 18:30:39.600: E/AndroidRuntime(334): Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
08-15 18:30:39.600: E/AndroidRuntime(334): at android.graphics.Bitmap.nativeCreate(Native Method)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:498)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:473)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.content.res.Resources.loadDrawable(Resources.java:1709)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.view.View.<init>(View.java:1951)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.widget.TextView.<init>(TextView.java:344)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.widget.Button.<init>(Button.java:108)
08-15 18:30:39.600: E/AndroidRuntime(334): at android.widget.Button.<init>(Button.java:104)
08-15 18:30:39.600: E/AndroidRuntime(334): ... 28 more
08-15 18:30:45.459: I/Process(334): Sending signal. PID: 334 SIG: 9
Heap sizes vary by device. It is perfectly reasonable that on devices where apps have large heap sizes you will encounter fewer problems than on devices where apps have smaller heap sizes. Your heap could be as low as 16MB, if you are supporting older/lower-resolution devices.
Most android has limited space. Usually 16MB. I highly suggest looking at your image size. Also use weak references where you can to make sure images are only using memory when accessed. (Weak references will force the garbage collected to clean them up quicker.)
And I don't know much about your app with just your logcat error list, but if you have multiple activities, kill the ones you don't need. Might seem like obvious advice, maybe not, but it will free up space.
As others stated, the heap size for an Application is limited. The minimum is 16MB and veries from device to device (it's a setting of the virtual machine).
Some suggestions what you could do:
You can load a smaller version of the image, if not needed in full resolution. Here is how to do it: http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html
Check if enough free memory is available; If memory gets low, you can just free images that are not directly needed right now and load them again, if they are needed.
Here is some code sniped for checking how much free memory is left:
long free = Runtime.getRuntime().freeMemory();
Caused by: java.lang.OutOfMemoryError: bitmap size exceeds VM budget
that line says it all.
The bitmaps are hogging all the memory of some devices (devices that the VM stack limit is higher). You should look into better memory management for this application such as LruCache, decode bitmaps with lower quality, etc.
edit:
do not use WeakReference as some users might suggest.
check this question Does Android need to load a complete Bitmap from a file before sampling it down? and also this video http://www.youtube.com/watch?v=gbQb1PVjfqM
direct explanations/teachings/techniques from the creators of the platform and say to not use WeakReference.
I am trying to send and receive port-directed SMS from an HTC EVO 4G to itself using SmsManager.sendDataMessage() and the device is giving a NullPointerException quite deep in the OS.
Here is the code that kicks off the exception:
manager.sendDataMessage(phonenumber, null, (short) 8091, data,piSend, piDelivered);
I think I have the appropriate permissions declared in the manifest:
<uses-permission android:name="android.permission.READ_SMS"></uses-permission>
<uses-permission android:name="android.permission.SEND_SMS"></uses-permission>
<uses-permission android:name="android.permission.RECEIVE_SMS"></uses-permission>
Here's the stack trace I'm getting:
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): FATAL EXCEPTION: main
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): java.lang.NullPointerException
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.os.Parcel.readException(Parcel.java:1328)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.os.Parcel.readException(Parcel.java:1276)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at com.android.internal.telephony.ISms$Stub$Proxy.sen dData(ISms.java:682)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.telephony.SmsManager.sendDataMessage(SmsMa nager.java:546)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at com.varma.samples.smsdemo.MainActivity.sendSms(Mai nActivity.java:66)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at com.varma.samples.smsdemo.MainActivity.access$0(Ma inActivity.java:50)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at com.varma.samples.smsdemo.MainActivity$1.onClick(M ainActivity.java:98)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.view.View.performClick(View.java:2532)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.view.View$PerformClick.run(View.java:9293)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.os.Handler.handleCallback(Handler.java:587 )
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.os.Handler.dispatchMessage(Handler.java:92 )
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.os.Looper.loop(Looper.java:143)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at android.app.ActivityThread.main(ActivityThread.jav a:4263)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at java.lang.reflect.Method.invokeNative(Native Method)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at java.lang.reflect.Method.invoke(Method.java:507)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at com.android.internal.os.ZygoteInit$MethodAndArgsCa ller.run(ZygoteInit.java:839)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at com.android.internal.os.ZygoteInit.main(ZygoteInit .java:597)
06-27 11:03:42.144: ERROR/AndroidRuntime(14489): at dalvik.system.NativeStart.main(Native Method)
If anybody wants to try it out for themselves, I am using the example provided here in the SMSDemo project.
Can anybody help me out with this?
EDIT :
I have just put together a sample J2ME MIDlet to see if I can get it to work as well and it also fails. Does anybody remember any information about port-directed SMS? Is it handled differently on different networks? Is it all just outdated and I need to get with the times? Or is it something that I might be doing?
In case SMS is network dependent, I'm using Sprint devices but I'm developing in Canada, so I think they are roaming on Telus.
I just got this stack trace from the marketplace error reporting and have no idea where to being to track the problem down, any help appreciated.
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.Bitmap.nativeCreate(Native Method)
at android.graphics.Bitmap.createBitmap(Bitmap.java:477)
at android.graphics.Bitmap.createBitmap(Bitmap.java:444)
at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:349)
at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:488)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:463)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:326)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
at android.content.res.Resources.loadDrawable(Resources.java:1709)
at android.content.res.Resources.getDrawable(Resources.java:581)
at com.android.internal.view.menu.MenuItemImpl.getIcon(MenuItemImpl.java:440)
at com.android.internal.view.menu.IconMenuItemView.initialize(IconMenuItemView.java:109)
at com.android.internal.view.menu.MenuItemImpl.createItemView(MenuItemImpl.java:594)
at com.android.internal.view.menu.MenuItemImpl.getItemView(MenuItemImpl.java:577)
at com.android.internal.view.menu.IconMenuView.updateChildren(IconMenuView.java:351)
at com.android.internal.view.menu.IconMenuView.initialize(IconMenuView.java:333)
at com.android.internal.view.menu.MenuBuilder$MenuType.getMenuView(MenuBuilder.java:199)
at com.android.internal.view.menu.MenuBuilder.getMenuView(MenuBuilder.java:323)
at com.android.internal.policy.impl.PhoneWindow.initializePanelContent(PhoneWindow.java:858)
at com.android.internal.policy.impl.PhoneWindow.openPanel(PhoneWindow.java:435)
at com.android.internal.policy.impl.PhoneWindow.onKeyUpPanel(PhoneWindow.java:621)
at com.android.internal.policy.impl.PhoneWindow.onKeyUp(PhoneWindow.java:1339)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1668)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at android.widget.TabHost.dispatchKeyEvent(TabHost.java:278)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:789)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:1687)
at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1120)
at android.app.Activity.dispatchKeyEvent(Activity.java:2073)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1663)
at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2560)
at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2535)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1867)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3647)
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:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
I'm getting the same error on an application I've developed for Android 2.1 and Android 2.2 but run on Android 4.0.1 ICS. The same app would run on Android 2.1 but cause a crash with the above error on ICS. If you're drawing something relatively big to the size of the screen, consider checking from that place.