2

The program loads ok, and I can go through a couple screens, but when the main.xml tries to load, the program crashes only on api 14.

logcat output:

04-26 09:02:14.290: E/AndroidRuntime(566): FATAL EXCEPTION: main
04-26 09:02:14.290: E/AndroidRuntime(566): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.surreall.yacht/com.surreall.yacht.yatzee}: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1955)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1980)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.ActivityThread.access$600(ActivityThread.java:122)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1146)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.os.Handler.dispatchMessage(Handler.java:99)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.os.Looper.loop(Looper.java:137)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.ActivityThread.main(ActivityThread.java:4340)
04-26 09:02:14.290: E/AndroidRuntime(566):  at java.lang.reflect.Method.invokeNative(Native Method)
04-26 09:02:14.290: E/AndroidRuntime(566):  at java.lang.reflect.Method.invoke(Method.java:511)
04-26 09:02:14.290: E/AndroidRuntime(566):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
04-26 09:02:14.290: E/AndroidRuntime(566):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
04-26 09:02:14.290: E/AndroidRuntime(566):  at dalvik.system.NativeStart.main(Native Method)
04-26 09:02:14.290: E/AndroidRuntime(566): Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.LayoutInflater.createView(LayoutInflater.java:606)
04-26 09:02:14.290: E/AndroidRuntime(566):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
04-26 09:02:14.290: E/AndroidRuntime(566):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.Activity.setContentView(Activity.java:1835)
04-26 09:02:14.290: E/AndroidRuntime(566):  at com.surreall.yacht.yatzee.onCreate(yatzee.java:211)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.Activity.performCreate(Activity.java:4465)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1919)
04-26 09:02:14.290: E/AndroidRuntime(566):  ... 11 more
04-26 09:02:14.290: E/AndroidRuntime(566): Caused by: java.lang.reflect.InvocationTargetException
04-26 09:02:14.290: E/AndroidRuntime(566):  at java.lang.reflect.Constructor.constructNative(Native Method)
04-26 09:02:14.290: E/AndroidRuntime(566):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.LayoutInflater.createView(LayoutInflater.java:586)
04-26 09:02:14.290: E/AndroidRuntime(566):  ... 23 more
04-26 09:02:14.290: E/AndroidRuntime(566): Caused by: java.lang.OutOfMemoryError
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.Bitmap.nativeCreate(Native Method)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.Bitmap.createBitmap(Bitmap.java:605)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.Bitmap.createBitmap(Bitmap.java:551)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.Bitmap.createScaledBitmap(Bitmap.java:437)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.BitmapFactory.finishDecode(BitmapFactory.java:524)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:499)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.content.res.Resources.loadDrawable(Resources.java:1937)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.View.<init>(View.java:2780)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.view.ViewGroup.<init>(ViewGroup.java:385)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.widget.LinearLayout.<init>(LinearLayout.java:174)
04-26 09:02:14.290: E/AndroidRuntime(566):  at android.widget.LinearLayout.<init>(LinearLayout.java:170)
04-26 09:02:14.290: E/AndroidRuntime(566):  ... 26 more

i can't post the contents of main.xml due to the 30k character question limit on stack overflow, and it is more than that. suggestions of where to start?

clayton33
  • 4,176
  • 10
  • 45
  • 64
  • i mentioned below, i tried running on a WVGA800 (480x800) resolution emulator that was API 14 (4.0) and it crashed with the same error but it runs fine on a WVGA800 with API 8 (2.2) and API 10 (2.3.3). – clayton33 Apr 29 '12 at 02:57
  • using the link in your comments zapl, i was able to determine that right before the crash, there is about 6mb in the heap precrash using api 8 or 10, and 23.5mb precrash using api 14 or 15. why is there such a big difference between the two? http://i.imgur.com/2dxyN.jpg android 2.3.3 api 10 http://i.imgur.com/RWujB.jpg android 4.0 api 14 all are using the 480x800 resolution...? – clayton33 May 01 '12 at 03:35

4 Answers4

2

found a similar problem here

apparently this was an issue with the heap size of the android emulator. I changed the "Max VM application heap size" in the AVD for the emulator i was using for the API 14, from 24 to 48 and it no longer crashes. it still doesn't quite explain why the API goes from using a heap of 6mb to 23.5mb, and i am hoping that the hardware on the end user devices all have at least a heapsize of 48mb otherwise their application will crash. for now i am marking this as fixed.

Community
  • 1
  • 1
clayton33
  • 4,176
  • 10
  • 45
  • 64
  • 1
    bad assumption, ive seen phones have a heap of 48mb and tablets with 32m. its all over the board, you can do a conditional statement based on heap size though (or fix your memory leak) – CQM May 04 '12 at 17:03
1

You try to load an image in your layout that is too big. See bottom of error message:

OutOfMemoryError
Resources.loadDrawable()

It is somwhere inside a LinearLayout

zapl
  • 63,179
  • 10
  • 123
  • 154
  • why would this image give a problem on api 14 but not on api 8? i have this game currently released on android market, and it only seems to get errors with tablets. – clayton33 Apr 29 '12 at 00:01
  • 1
    two things I can imagine: a) the image seems to get scaled possibly to a bigger screen (tablet?) and scaled uses more memory (4x the pixels in bytes) b) you have different drawables in e.g. `x-large` or `hdpi` that are not commonly used on other devices and the image there is simply too big. – zapl Apr 29 '12 at 00:05
  • i have only one set of images in my drawable folder, so it must be the first case. is there a way of either allocating more memory for the game, or preventing the game from using as much? they are not very big images as it is, if i scale them much smaller, the resolution will become noticeable. the entire game is already only less than 2mb. – clayton33 Apr 29 '12 at 00:13
  • 1
    even a small png will need much memory if it is upscaled to 1280x720 (4MB) although I don't know if there is actually code that upscales. It is usually downscaling that is done the other way does not make sense, maybe for 9patch images. And there is [android:largeHeap](http://stackoverflow.com/questions/6075276/largeheap-true-manifest-tag-not-working) which you could try. – zapl Apr 29 '12 at 00:43
  • i tried running on a WVGA800 (480x800) resolution emulator that was API 14 (4.0) and it crashed with the same error. it runs fine on a WVGA800 with API 8 (2.2) and API 10 (2.3.3). – clayton33 Apr 29 '12 at 02:48
  • 1
    Not sure if that works during that stage but you could try to use http://android-developers.blogspot.de/2011/03/memory-analysis-for-android.html to check how much memory your app uses and maybe find out why. – zapl Apr 29 '12 at 02:55
  • there is definitely something different going on, it goes from using 6mb heap to using 23.5mb heap, but i have been trying for 3 days now to figure out why... the full size of the /drawable folder is 393k, i can't figure out where this 23.5mb is coming from?! – clayton33 May 01 '12 at 03:40
  • small filesize does not mean small memory footprint and even if that is the case then loading them multiple times into memory can easily get you to those 23.5MB – zapl May 01 '12 at 23:22
1

according to my experience , it can also occur on a real device - the exact same out-of-memory exception occured for me on the galaxy nexus . i think it occurs because of the resolution .

here are possible solutions:

  1. sample the images according to your need.
  2. set a larger heap size in the manifest.
  3. if the images are static , create your own imageView alternative , which only shows the image and after that doesn't hold a reference to it (or use softreference and a builder instead) .
  4. use opengl /ndk or whatever framework that can bypass the heap size limit .
  5. in any case , do not store all of your images . instead , store only those that you need currently , and the rest can stay in your cache (which could be LRU cache or softreference cache ) .
android developer
  • 114,585
  • 152
  • 739
  • 1,270
0

Check if the problem is not related to hardware acceleration that is enabled as default since API 14, More information Here:

http://developer.android.com/guide/topics/graphics/hardware-accel.html

In one application that I was working on we got crashes on one specific View and it was caused by hardware acceleration enabled by API 14. The link above shows how to disable it in several levels, in my case a just disabled it at View Level since disabling for the whole application causes some issues if you are trying to use new themes (introduced since ICS).