There is a custom ExpandableListView, where data from the database is displayed, if there is more data in the drop-down list than is displayed on the screen and I start scrolling the list, the application crashes on the phone, did not notice something on the emulator. Why can this happen?

Here is a glass

Process: test.myapp, PID: 12547 java.lang.OutOfMemoryError: Failed to allocate a 4905612 byte allocation with 961968 free bytes and 939KB until OOM at dalvik.system.VMRuntime.newNonMovableArray(Native Method) at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method) at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:856) at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:675) at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:2228) at android.content.res.Resources.loadDrawableForCookie(Resources.java:4211) at android.content.res.Resources.loadDrawable(Resources.java:4085) at android.content.res.Resources.getDrawable(Resources.java:2005) at android.content.res.Resources.getDrawable(Resources.java:1987) at android.content.Context.getDrawable(Context.java:464) at android.widget.ImageView.resolveUri(ImageView.java:827) at android.widget.ImageView.setImageResource(ImageView.java:434) at de.hdodenhof.circleimageview.CircleImageView.setImageResource(CircleImageView.java:290) at test.myapp.ExpListAdapter.bindChildView(ExpListAdapter.java:87) at android.widget.CursorTreeAdapter.getChildView(CursorTreeAdapter.java:251) at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:451) at android.widget.AbsListView.obtainView(AbsListView.java:2934) at android.widget.ListView.makeAndAddView(ListView.java:1945) at android.widget.ListView.fillDown(ListView.java:719) at android.widget.ListView.fillSpecific(ListView.java:1391) at android.widget.ListView.layoutChildren(ListView.java:1712) at android.widget.AbsListView.onLayout(AbsListView.java:2728) at android.view.View.layout(View.java:17972) at android.view.ViewGroup.layout(ViewGroup.java:5814) at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1080) at android.view.View.layout(View.java:17972) at android.view.ViewGroup.layout(ViewGroup.java:5814) at android.support.design.widget.HeaderScrollingViewBehavior.layoutChild(HeaderScrollingViewBehavior.java:131) at android.support.design.widget.ViewOffsetBehavior.onLayoutChild(ViewOffsetBehavior.java:42) at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onLayoutChild(AppBarLayout.java:1375) at android.support.design.widget.CoordinatorLayout.onLayout(CoordinatorLayout.java:870) at android.view.View.layout(View.java:17972) at android.view.ViewGroup.layout(ViewGroup.java:5814) at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:1193) at android.view.View.layout(View.java:17972) at android.view.ViewGroup.layout(ViewGroup.java:5814) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344) at android.widget.FrameLayout.onLayout(FrameLayout.java:281) at android.view.View.layout(View.java:17972) at android.view.ViewGroup.layout(ViewGroup.java:5814) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585) at android.widget.LinearLayout.onLayout(LinearLayout.java:1494) at android.view.View.layout(View.java:17972) at android.view.ViewGroup.layout(ViewGroup.java:5814) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344) at android.widget.FrameLayout.onLayout(FrameLayout.java:281) at android.view.View.layout(View.java:17972) at android.view.ViewGroup.layout(ViewGroup.java:5814) at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1742) at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1585) at android.widget.LinearLayout.onLayout(LinearLayout.java:1494) at android.view.View.layout(View.java:17972) at android.view.ViewGroup.layout(ViewGroup.java:5814) at android.widget.FrameLayout.layoutChildren(FrameLayout.java:344) at android.widget.FrameLayout.onLayout(FrameLayout.java:281) at com.android.internal.policy.PhoneWindow$DecorView.onLayout(PhoneWindow.java:3129) at android.view.View.layout(View.java:17972) at android.view.ViewGroup.layout(ViewGroup.java:5 

Here is the problem code itself

 public class ExpListAdapter extends SimpleCursorTreeAdapter { DBHeler dbHeler; private int layout; public ExpListAdapter(Context context, Cursor cursor, int groupLayout, String[] groupFrom, int[] groupTo, int childLayout, String[] childFrom, int[] childTo) { super(context, cursor, groupLayout, groupFrom, groupTo, childLayout, childFrom, childTo); dbHeler = new DBHeler(context); this.layout = childLayout; } public static class ViewHolder { public CircleImageView imgView; public TextView txtName; public TextView txtHistory; public ImageButton btnFavorite; public ViewHolder(View view) { imgView = (CircleImageView) view.findViewById(R.id.imgView); txtName = (TextView) view.findViewById(R.id.txtName); txtHistory = (TextView) view.findViewById(R.id.txtHistory); btnFavorite = (ImageButton) view.findViewById(R.id.btnFavorite); } } @Override protected Cursor getChildrenCursor(Cursor groupCursor) { int idColumn = groupCursor.getColumnIndex(Contract.Entry._ID); return dbHeler.getBluda(groupCursor.getInt(idColumn)); } @Override public View newChildView(Context context, Cursor cursor, boolean isLastChild, ViewGroup parent) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(layout, parent, false); ViewHolder viewHolder = new ViewHolder(view); view.setTag(viewHolder); return view; } @Override protected void bindChildView(View view, Context context, Cursor cursor, boolean isLastChild) { ViewHolder holder = (ViewHolder) view.getTag(); int _ID = cursor.getInt(cursor.getColumnIndex(Contract.Entry._ID)); String name = cursor.getString(cursor.getColumnIndex(Contract.Entry.COLUMN_NAME)); String history = cursor.getString(cursor.getColumnIndex(Contract.Entry.COLUMN_history)); String image = cursor.getString(cursor.getColumnIndex(Contract.Entry.COLUMN_IMAGE)); String favorite = cursor.getString(cursor.getColumnIndex(Contract.Entry.COLUMN_FAVORITE)); holder.txtName.setText(name); holder.txtHistory.setText(history); holder.btnFavorite.setFocusable(false); if (favorite.equals("0")) { holder.btnFavorite.setImageResource(R.drawable.icon_star_outline_black); } else { holder.btnFavorite.setImageResource(R.drawable.icon_star_yellow); } Resources resources = context.getResources(); int resId = resources.getIdentifier(image, "raw", context.getPackageName()); holder.imgView.setImageResource(resId); holder.btnFavorite.setTag(new Dost(_ID, name, history, resId, favorite)); } } 

I redid the application like here Filtering ListView data using CursorLoader . Sometimes I noticed this when I open the first group, where I have the most nested items and start scrolling, the application closes, while nothing is displayed in the system frame that looks like an error, and if we open the second group, let's say, and then the first one started scrolling. described

  • an error means that you have a memory overflow crash when loading images. Their size is too big for the device under test - pavlofff
  • The fact is that when they are loaded onto the screen, they are processed (scaled, etc.) and there may not be enough memory for these operations with a sufficient number of images, which we observe. Also in terms of size, their geometrical dimensions in pixels matter, and not just the file size. In general, you need to optimize for this parameter, it is possible to first try to use something like Picasso or Glide - pavlofff
  • Fine. It is recommended to use images in the .png format - it is more optimized, and it’s better not to store these images in res / raw, for them there are res / drawable - pavlofff
  • Stektreys indicates a lack of memory in the processing of graphic files, rather than loading data. - pavlofff
  • sort of decided. Made 100 per 100 picture size) - Veronika

0