Here is what I am doing
ImageView image2 = (ImageView) findViewById(R.id.imageView3);
image2.getDrawable().setCallback(null);
image2.setImageResource(R.drawable.fire);
where fire is an xml file proposing an animation drawable
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="#drawable/fire1" android:duration="50" />
<item android:drawable="#drawable/fire2" android:duration="50" />
<item android:drawable="#drawable/fire3" android:duration="50" />
<item android:drawable="#drawable/fire4" android:duration="50" />
<item android:drawable="#drawable/fire5" android:duration="50" />
...
<item android:drawable="#drawable/fire16" android:duration="50" />
I have this error
02-12 11:37:20.919: E/dalvikvm-heap(3193): 1535664-byte external allocation too large for this process.
02-12 11:37:20.959: E/GraphicsJNI(3193): VM won't let us allocate 1535664 bytes
02-12 11:37:20.959: W/dalvikvm(3193): threadid=1: thread exiting with uncaught exception (group=0x40018560)
02-12 11:37:20.979: E/AndroidRuntime(3193): FATAL EXCEPTION: main
02-12 11:37:20.979: E/AndroidRuntime(3193): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:460)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:336)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.content.res.Resources.loadDrawable(Resources.java:1709)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.content.res.Resources.getDrawable(Resources.java:581)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.graphics.drawable.AnimationDrawable.inflate(AnimationDrawable.java:267)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:787)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.graphics.drawable.Drawable.createFromXml(Drawable.java:728)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.content.res.Resources.loadDrawable(Resources.java:1694)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.content.res.Resources.getDrawable(Resources.java:581)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.widget.ImageView.resolveUri(ImageView.java:501)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.widget.ImageView.setImageResource(ImageView.java:280)
02-12 11:37:20.979: E/AndroidRuntime(3193): at com.example.kersplatt.GameActivity.onCreate(GameActivity.java:71)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.os.Handler.dispatchMessage(Handler.java:99)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.os.Looper.loop(Looper.java:130)
02-12 11:37:20.979: E/AndroidRuntime(3193): at android.app.ActivityThread.main(ActivityThread.java:3683)
02-12 11:37:20.979: E/AndroidRuntime(3193): at java.lang.reflect.Method.invokeNative(Native Method)
02-12 11:37:20.979: E/AndroidRuntime(3193): at java.lang.reflect.Method.invoke(Method.java:507)
02-12 11:37:20.979: E/AndroidRuntime(3193): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:875)
02-12 11:37:20.979: E/AndroidRuntime(3193): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:633)
02-12 11:37:20.979: E/AndroidRuntime(3193): at dalvik.system.NativeStart.main(Native Method)
I read so many threads about memory leaks, memory errors (for instance java.lang.OutOfMemoryError: bitmap size exceeds VM budget - Android) but I didn't succeed in solving my problem
When I remplace image2.setImageResource(R.drawable.fire); by image2.setImageResource(R.drawable.fire1); where fire1 is a simple png, everything works fine
What could I do to solve my problem
To remove OutOfMemory error, you should focus on scaling. You can find at http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
Related
After updating my app is crashing while starting with the following stacktrace:
02-12 14:01:26.158: W/System(8631): ClassLoader referenced unknown path: /data/app/com.example.ib-2/lib/arm
02-12 14:01:26.222: D/AndroidRuntime(8631): Shutting down VM
02-12 13:36:30.061: E/AndroidRuntime(7312): FATAL EXCEPTION: main
02-12 13:36:30.061: E/AndroidRuntime(7312): Process: com.example.ib, PID: 7312
02-12 13:36:30.061: E/AndroidRuntime(7312): java.lang.NoSuchFieldError: No static field View_theme of type I in class Landroid/support/v7/appcompat/R$styleable; or its superclasses (declaration of 'android.support.v7.appcompat.R$styleable' appears in /data/app/com.example.ib-1/base.apk)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.support.v7.app.AppCompatViewInflater.themifyContext(AppCompatViewInflater.java:229)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:84)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.support.v7.app.AppCompatDelegateImplV7.createView(AppCompatDelegateImplV7.java:938)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:992)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
02-12 13:36:30.061: E/AndroidRuntime(7312): at com.android.internal.policy.PhoneWindow.generateLayout(PhoneWindow.java:3909)
02-12 13:36:30.061: E/AndroidRuntime(7312): at com.android.internal.policy.PhoneWindow.installDecor(PhoneWindow.java:3981)
02-12 13:36:30.061: E/AndroidRuntime(7312): at com.android.internal.policy.PhoneWindow.getDecorView(PhoneWindow.java:1969)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.support.v7.app.AppCompatDelegateImplV7.onCreate(AppCompatDelegateImplV7.java:149)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.support.v7.app.AppCompatActivity.onCreate(AppCompatActivity.java:60)
02-12 13:36:30.061: E/AndroidRuntime(7312): at com.example.ib.MainActivity.onCreate(MainActivity.java:77)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.app.Activity.performCreate(Activity.java:6251)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.app.ActivityThread.-wrap11(ActivityThread.java)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.os.Handler.dispatchMessage(Handler.java:102)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.os.Looper.loop(Looper.java:148)
02-12 13:36:30.061: E/AndroidRuntime(7312): at android.app.ActivityThread.main(ActivityThread.java:5417)
02-12 13:36:30.061: E/AndroidRuntime(7312): at java.lang.reflect.Method.invoke(Native Method)
02-12 13:36:30.061: E/AndroidRuntime(7312): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
02-12 13:36:30.061: E/AndroidRuntime(7312): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
I have copied appcompat jar files to the imported appcompat project, still, it doesn't work. Please help
Helllo,
I got this problem with ViewPagerAdapter. On various phones it sometimes crashes and sometimes not and can't put my finger on the cause. I even made largeHeap for API>14 and still got this on. Anyone know what's going on?
java.lang.OutOfMemoryError: bitmap size exceeds VM budget
at android.graphics.BitmapFactory.nativeDecodeAsset(BitmapFactory.java)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:563)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:439)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:697)
at android.content.res.Resources.loadDrawable(Resources.java:1981)
at android.content.res.Resources.getDrawable(Resources.java:601)
at android.widget.ImageView.resolveUri(ImageView.java:501)
at android.widget.ImageView.setImageResource(ImageView.java:280)
at com.example.package.ViewPagerAdapter.instantiateItem(ViewPagerAdapter.java:85)
at android.support.v4.view.ViewPager.addNewItem(ViewPager.java:832)
at android.support.v4.view.ViewPager.populate(ViewPager.java:1048)
at android.support.v4.view.ViewPager.populate(ViewPager.java:914)
at android.support.v4.view.ViewPager$3.run(ViewPager.java:244)
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:3691)
at java.lang.reflect.Method.invokeNative(Method.java)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(NativeStart.java)
I am having a little trouble. I am completely new at this. I am trying to get my app to start with a splash screen then continue on to a new activity, but my app keeps force closing with a fatal exception:main. this is the logcat
02-12 02:56:32.989: D/AndroidRuntime(1487): Shutting down VM
02-12 02:56:32.989: W/dalvikvm(1487): threadid=1: thread exiting with uncaught exception (group=0x4001e560)
02-12 02:56:33.009: E/AndroidRuntime(1487): FATAL EXCEPTION: main
02-12 02:56:33.009: E/AndroidRuntime(1487): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.madonk.LAFEST/com.madonk.LAFEST.MAIN}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
02-12 02:56:33.009: E/AndroidRuntime(1487): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1702)
02-12 02:56:33.009: E/AndroidRuntime(1487): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1722)
02-12 02:56:33.009: E/AndroidRuntime(1487): at android.app.ActivityThread.access$1500(ActivityThread.java:124)
02-12 02:56:33.009: E/AndroidRuntime(1487): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:974)
02-12 02:56:33.009: E/AndroidRuntime(1487): at android.os.Handler.dispatchMessage(Handler.java:99)
02-12 02:56:33.009: E/AndroidRuntime(1487): at android.os.Looper.loop(Looper.java:130)
02-12 02:56:33.009: E/AndroidRuntime(1487): at android.app.ActivityThread.main(ActivityThread.java:3821)
02-12 02:56:33.009: E/AndroidRuntime(1487): at java.lang.reflect.Method.invokeNative(Native Method)
02-12 02:56:33.009: E/AndroidRuntime(1487): at java.lang.reflect.Method.invoke(Method.java:507)
02-12 02:56:33.009: E/AndroidRuntime(1487): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
02-12 02:56:33.009: E/AndroidRuntime(1487): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
02-12 02:56:33.009: E/AndroidRuntime(1487): at dalvik.system.NativeStart.main(Native Method)
02-12 02:56:33.009: E/AndroidRuntime(1487): Caused by: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
02-12 02:56:33.009: E/AndroidRuntime(1487): at android.app.ListActivity.onContentChanged(ListActivity.java:243)
02-12 02:56:33.009: E/AndroidRuntime(1487): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:256)
02-12 02:56:33.009: E/AndroidRuntime(1487): at android.app.Activity.setContentView(Activity.java:1716)
02-12 02:56:33.009: E/AndroidRuntime(1487): at com.madonk.LAFEST.MAIN.onCreate(MAIN.java:17)
02-12 02:56:33.009: E/AndroidRuntime(1487): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-12 02:56:33.009: E/AndroidRuntime(1487): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1666)
02-12 02:56:33.009: E/AndroidRuntime(1487): ... 11 more
If there is anything anyone can do to help, I would greatly appreciate it.
Your activity probably extends ListActivity and because of this in your xml file containing the layout of your activity(the one you set with setContentView(R.layout.name_of_layout)) you must have a ListView element with the id:
<ListView android:id="#android:id/list"
//other attributes
>
Ive follow the tutoria about how to make activity Gallery on [android-developer][1]
[1]: http://developer.android.com/guide/tutorials/views/hello-gallery.html but i got the next error:
02-12 17:54:06.221: ERROR/AndroidRuntime(1330): Uncaught handler: thread main exiting due to uncaught exception
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.addsensor.CameraMap/com.addsensor.CameraMap.GalleryCamera}: java.lang.NullPointerException
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2268)
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2284)
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at android.app.ActivityThread.access$1800(ActivityThread.java:112)
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1692)
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at android.os.Handler.dispatchMessage(Handler.java:99)
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at android.os.Looper.loop(Looper.java:123)
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at android.app.ActivityThread.main(ActivityThread.java:3948)
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at java.lang.reflect.Method.invokeNative(Native Method)
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at java.lang.reflect.Method.invoke(Method.java:521)
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at dalvik.system.NativeStart.main(Native Method)
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): Caused by: java.lang.NullPointerException
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at com.addsensor.CameraMap.GalleryCamera.onCreate(GalleryCamera.java:20)
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
02-12 17:54:06.301: ERROR/AndroidRuntime(1330): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
I have also change one thing which someone comment here, on [stackoverflow][1]
[1]: Android Hello, Gallery tutorial -- "R.styleable cannot be resolved" but i am still getting the error. Its a simple activity and i dont know how to follow. Anyone knows?¿ or how to fix it?¿
thanks
You are trying to use a reference to null (e.g. variable uninitialized, etc..) in CameraMap.GalleryCamera,onCreate() method, line 20.
Please post code for this method (and indicate line number 20).
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.