Reputation: 5472
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.
Upvotes: 2
Views: 552
Reputation:
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
Upvotes: 1
Reputation: 10338
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.
Upvotes: 0