2

I'm using the class posted on StackOverflow

and I just had a OutOfMemoryError:

Giving StackTrace:

android.view.InflateException: Binary XML file line #15: Error inflating class at android.view.LayoutInflater.createView(LayoutInflater.java:626) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:702) at android.view.LayoutInflater.rInflate(LayoutInflater.java:761) at android.view.LayoutInflater.rInflate(LayoutInflater.java:769) at android.view.LayoutInflater.inflate(LayoutInflater.java:498) at android.view.LayoutInflater.inflate(LayoutInflater.java:398) at com.flunny.fragments.amici.TrovaAmiciFragment$TrovaAmiciAdapter.getView(TrovaAmiciFragment.java:158) at android.widget.AbsListView.obtainView(AbsListView.java:2608) at android.widget.ListView.makeAndAddView(ListView.java:1852) at android.widget.ListView.fillDown(ListView.java:682) at android.widget.ListView.fillGap(ListView.java:646) at android.widget.AbsListView.trackMotionScroll(AbsListView.java:6592) at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:5575) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:791) at android.view.Choreographer.doCallbacks(Choreographer.java:591) at android.view.Choreographer.doFrame(Choreographer.java:560) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:777) at android.os.Handler.handleCallback(Handler.java:730) at android.os.Handler.dispatchMessage(Handler.java:92) at android.os.Looper.loop(Looper.java:176) at android.app.ActivityThread.main(ActivityThread.java:5419) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:525) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1046) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:862) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.reflect.InvocationTargetException at java.lang.reflect.Constructor.constructNative(Native Method) at java.lang.reflect.Constructor.newInstance(Constructor.java:417) at android.view.LayoutInflater.createView(LayoutInflater.java:600) ... 25 more Caused by: 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.TypedArray.getDrawable(TypedArray.java:602) at android.widget.ImageView.(ImageView.java:131) at com.flunny.resources.CircularImageView.(CircularImageView.java:33) at com.flunny.resources.CircularImageView.(CircularImageView.java:29) ... 28 more

XML #15 is:

 <com.flunny.resources.CircularImageView
     android:id="@+id/circularImageView1"
     android:layout_width="@dimen/trovaAmiciImmagineAltezza"
     android:layout_height="@dimen/trovaAmiciImmagineAltezza"
     android:layout_centerVertical="true"
     android:src="@drawable/sconosciuto" />

CircularImageView #33 and #29:

public CircularImageView(Context context, AttributeSet attrs) {
    this(context, attrs, R.attr.circularImageViewStyle); // 29
}

public CircularImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle); // 33
................

Image wasn't set, it crashed before (or not?). The default image (@drawable/sconosciuto) has 2,9kb (111px x 111px).

And the rest of the images are loaded by ImageLoader but they are not more than 20 kb

Thanks in advance.

Community
  • 1
  • 1
Rafael Ruiz Muñoz
  • 5,333
  • 6
  • 46
  • 92

2 Answers2

1

May be you are using list view and you are initializing you image view again and again

public View getView(int position, View convertView, ViewGroup parent) {

        View listitem = convertView;
        int pos = position;

        if (convertView == null) {
            /** Inflating the List Item below */

            /** Getting the Image View of Listitem below */
            textOfRank = (TextView) listitem
                    .findViewById(R.id.textview_of_Rank);
            textOfErrors = (TextView) listitem
                    .findViewById(R.id.textview_of_Errors);
            textOfMode = (TextView) listitem
                    .findViewById(R.id.textview_of_Mode);
            textOfTime = (TextView) listitem
                    .findViewById(R.id.textview_of_Time);

        }
}

if i am not wrong so just initialize you Image view or any thing just once in your adapter class thank you may be it will help you

ArtKorchagin
  • 4,801
  • 13
  • 42
  • 58
  • I think this is the problem, seems your listview has problems filling the heap. Investigate this part of code – Sulfkain May 28 '14 at 16:10
  • Hi, yes, I need to load it again because the state changes (imagine Facebook's friend request: I accept, it's loading, "You are friend", so I need to load it everytime. What should I do then? – Rafael Ruiz Muñoz May 28 '14 at 17:49
0

Applications are provided a heap-size memory during their creation. You got outofmemory error because your heapsize exceeded the provided by the system. To avoid it you need to scale your image (change the size of bitmap loaded in memory) and then manipulate it. Note that bitmap consume more memory than the file they are loaded from because in filesystem they are compressed but in ram they are not. Alternately not a good practice but you can request a bigger heap size by android:largeHeap="true" to true.

Illegal Argument
  • 10,090
  • 2
  • 44
  • 61
  • Excuse me, this seems a copy-paste reply. I said it has a small size (111x111 px < is it a large size?) and I manipulate it with ImageLoader. – Rafael Ruiz Muñoz May 28 '14 at 14:40
  • Its not a copy paste reply I can assure you that but I was busy looking at your stack trace and got carried away will look at it again – Illegal Argument May 28 '14 at 14:43