-1

i have a problem. My app was normally working, but when i added new ImageView in layout XML, it's crashing. Is it because there are too many imageviews in one activity or too much memory? The image has 511 kb and resolution 733 x 3999.

Here is my crash log:

10-19 14:09:04.762: E/AndroidRuntime(15605): FATAL EXCEPTION: main
10-19 14:09:04.762: E/AndroidRuntime(15605): Process: com.formulas.mpc, PID: 15605
10-19 14:09:04.762: E/AndroidRuntime(15605): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.formulas.mpc/com.formulas.mpc.ActivityPhysicsMenu}: android.view.InflateException: Binary XML file line #295: Error inflating class <unknown>
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2237)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2286)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.app.ActivityThread.access$800(ActivityThread.java:144)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1246)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.os.Handler.dispatchMessage(Handler.java:102)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.os.Looper.loop(Looper.java:212)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.app.ActivityThread.main(ActivityThread.java:5135)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at java.lang.reflect.Method.invokeNative(Native Method)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at java.lang.reflect.Method.invoke(Method.java:515)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at dalvik.system.NativeStart.main(Native Method)
10-19 14:09:04.762: E/AndroidRuntime(15605): Caused by: android.view.InflateException: Binary XML file line #295: Error inflating class <unknown>
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.view.LayoutInflater.createView(LayoutInflater.java:620)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:669)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:694)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:758)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:297)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.app.Activity.setContentView(Activity.java:1929)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:110)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at com.formulas.mpc.ActivityPhysicsMenu.onCreate(ActivityPhysicsMenu.java:20)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.app.Activity.performCreate(Activity.java:5231)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2201)
10-19 14:09:04.762: E/AndroidRuntime(15605):    ... 11 more
10-19 14:09:04.762: E/AndroidRuntime(15605): Caused by: java.lang.reflect.InvocationTargetException
10-19 14:09:04.762: E/AndroidRuntime(15605):    at java.lang.reflect.Constructor.constructNative(Native Method)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.view.LayoutInflater.createView(LayoutInflater.java:594)
10-19 14:09:04.762: E/AndroidRuntime(15605):    ... 28 more
10-19 14:09:04.762: E/AndroidRuntime(15605): Caused by: java.lang.OutOfMemoryError
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:594)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:429)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:856)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.content.res.Resources.loadDrawable(Resources.java:2129)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.content.res.TypedArray.getDrawable(TypedArray.java:602)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.widget.ImageView.<init>(ImageView.java:129)
10-19 14:09:04.762: E/AndroidRuntime(15605):    at android.widget.ImageView.<init>(ImageView.java:119)
10-19 14:09:04.762: E/AndroidRuntime(15605):    ... 31 more
  • its not about image size , check your xml code – Mina Fawzy Oct 19 '14 at 12:20
  • possible duplicate of [Android: BitmapFactory.decodeStream() out of memory with a 400KB file with 2MB free heap](http://stackoverflow.com/questions/11820266/android-bitmapfactory-decodestream-out-of-memory-with-a-400kb-file-with-2mb-f) – ToYonos Oct 19 '14 at 12:26

3 Answers3

0

Your question itself has the answer. Youu are using too many image views that's the reason the app is crashing. If possible reduce the number of images views by replacing image views by simple layouts and adding backgrounds to them.

Nandan Bhat
  • 1,573
  • 2
  • 9
  • 21
0

its not the number of images bro.. its the resolution of your images..

733 x 3999 //c'mon bro are you design for a big tablet?

and plus you have many of them with that resolution thats y trim them to lets say 400 * 400

Elltz
  • 10,730
  • 4
  • 31
  • 59
  • Well, i have long text, that I needed to format and put some photos to it, so it must be in bigger resolution... But thanks, i cut it to 458x2500 and it works! How can i make it look like 733x3999? Just change layout_width and lenght to px? – user3932494 Oct 19 '14 at 12:41
  • 1
    there is this phrase "the bigger your new years resolution the better it becomes".. yes so the bigger the size, the clearer it looks, so if you really want to have a desktop look resolution pic, on a small device, its not gonna work.. 458*2500 might even crash on QVGA (240x320) device..referenced from the link i gave before in my answer, so to answer your next question apply that for tablet and for your phones follow the documentation... happy coding. – Elltz Oct 19 '14 at 12:51
  • and if you try to stretch it using width and length is gonna look stretched and blurry- which aint nice.. so play around the size you see fit.. use scaleType = "Fitx-y"; -(i dont quite recall the format, but put scaleType fit x and y).. to fit the image in the image view to match your preferred size – Elltz Oct 19 '14 at 12:59
0

As we know , In android, allocation of memory is very less for image so whenever size of image is larger than allocated heap memmory then we get outOfMemory Exception.

So It is mainly because of the size of the image , please decrease the size of the image according to the devices in multiple drawables folder of the project. and after this you will not be getting this kind of error.

Please use the standard size of images according to devices.
plaese see this : http://developer.android.com/guide/practices/screens_support.html

Nitesh Singh
  • 328
  • 3
  • 13