title: Android - fragment with three listviews crashes with out of memory error
body: <p>I've made this simple fragment layout -</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="horizontal" &gt;
  
      &lt;ListView
          android:id="@+id/listView_airplanes"
          android:layout_width="170dp"
          android:layout_height="wrap_content" &gt;
      &lt;/ListView&gt;
  
      &lt;ListView
          android:id="@+id/listView_fruits"
          android:layout_width="170dp"
          android:layout_height="wrap_content" &gt;
      &lt;/ListView&gt;
  
      &lt;ListView
          android:id="@+id/listView_animals"
          android:layout_width="170dp"
          android:layout_height="wrap_content" &gt;
      &lt;/ListView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Now each row in each of those listviews should show an image that sits in the assets folder.</p>
  
  <p>so the layout of each list item is like this -</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="horizontal" &gt;
  
      &lt;ImageView
          android:id="@+id/imageView_image"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/@null" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Now, I've made a layout for each one of the listview, but it all look the same - just one imageview in it.</p>
  
  <p>Now for the code -</p>
  
  <pre><code>        @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
  View v = inflater.inflate(R.layout.listsviews,container, false);
  
   lvTops = (ListView) v.findViewById(R.id.listView_airplanes);
           lvBottoms = (ListView) v.findViewById(R.id.listView_fruits);
           lvMiddle = (ListView) v.findViewById(R.id.listView_animals);
  
  dbHand = new DbHandler(getActivity());
  
  Cursor topCursor = dbHand.queryByCat("airplanes);
  Cursor bottomCursor = dbHand.queryByCat("fruits");
  Cursor middleCursor = dbHand.queryByCat("animals");
  
  
              getActivity().startManagingCursor(topCursor);
  
  
              getActivity().startManagingCursor(bottomCursor);
  
  
              getActivity().startManagingCursor(middleCursor);
  
              topadp = new TopsAdptor(getActivity(), topCursor);
              lvTops.setAdapter(topadp);
  
              botadp = new BottomsAdaptor(getActivity(), bottomCursor);
              lvBottoms.setAdapter(botadp);
  
              middleCursor = new MiddleAdptor(getActivity(), topCursor);
              lvMiddle.setAdapter(topadp);
  
  
  
  }
  </code></pre>
  
  <p>As you can see I'm using a custom adapter class for each one of the listviews.</p>
  
  <p>All the adapters code are the same -so here's an example -</p>
  
  <pre><code>    class BottomsAdaptor extends CursorAdapter {
  
      public BottomsAdaptor(Context context, Cursor c) {
          super(context, c);
          // TODO Auto-generated constructor stub
      }
  
      @Override
      public void bindView(View view, Context context, Cursor cursor) {
          // TODO Auto-generated method stub
          String pic = cursor.getString(cursor
                  .getColumnIndex(Constants.ITEM_PIC_URL));
  
          ImageView iv = (ImageView) view.findViewById(R.id.imageView_lv_bottom);
  
  
  
  
          try {
              InputStream ims;
              ims = getActivity().getAssets().open(pic);
              Drawable d = Drawable.createFromStream(ims, null);
              iv.setImageDrawable(d);
  
          } catch (IOException e) {
  
  
              e.printStackTrace();
          }
  
  
      }
  
      @Override
      public View newView(Context arg0, Cursor arg1, ViewGroup parent) {
          // TODO Auto-generated method stub
          return getActivity().getLayoutInflater().inflate(R.layout.bottoms_list_item, parent,
                  false);
      }
  
  }
  </code></pre>
  
  <p>Now the thing is that in small numbers of images (let's say 5 for each listview) it sure seems to work fine, but when I raise the number of images in each listview, then while scrolling down at one of the listview the app is crashing and in the log it says -</p>
  
  <pre><code>java.lang.OutOfMemoryError
  </code></pre>
  
  <p>Now I've also tried to use asynctask  like so -</p>
  
  <pre><code>    class Asyinc extends AsyncTask&lt;Void, Void, Void&gt;{
       Cursor topCursor;
       Cursor bottomCursor;
       Cursor middleCursor;
  
      @Override
      protected Void doInBackground(Void... params) {
  
           topCursor = dbHand.queryByCat("tops");
           bottomCursor = dbHand.queryByCat("bottoms");
           middleCursor;= dbHand.queryByCat("dress");
  
  
          getActivity().startManagingCursor(topCursor);
  
          getActivity().startManagingCursor(bottomCursor);
          getActivity().startManagingCursor(middleCursor);
  
  
          return null;
      }
  
      @Override
      protected void onPostExecute(Void result) {
  
          super.onPostExecute(result);
  
  
          topadp = new TopsAdptor(getActivity(), topCursor);
          lvTops.setAdapter(topadp);
  
  
          botadp = new BottomsAdaptor(getActivity(), bottomCursor);
          lvBottoms.setAdapter(botadp);
  
  
          middleatp = new DressedAdptor(getActivity(), middleCursor);
          lvMiddle.setAdapter(middleatp);
  
  
  
  
      }
  
  }
  </code></pre>
  
  <p>But still the app is crashing while trying to scrolling in the listviews.</p>
  
  <p>Any ideas how may i solved this?
  Thanks for any kind of help</p>
  
  <p>Here's the logcat error, when I used the asynctask  - </p>
  
  <pre><code>    11-15 00:54:15.635: E/AndroidRuntime(4050): FATAL EXCEPTION: main
  11-15 00:54:15.635: E/AndroidRuntime(4050): java.lang.OutOfMemoryError
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:500)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:353)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:781)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.graphics.drawable.Drawable.createFromStream(Drawable.java:741)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at com.example.app1.MyFrag$BottomsAdaptor.bindView(MywordFrag.java:262)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.support.v4.widget.CursorAdapter.getView(CursorAdapter.java:256)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.widget.AbsListView.obtainView(AbsListView.java:2267)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.widget.ListView.makeAndAddView(ListView.java:1769)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.widget.ListView.fillDown(ListView.java:672)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.widget.ListView.fillGap(ListView.java:636)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5036)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.widget.AbsListView.scrollIfNeeded(AbsListView.java:3193)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.widget.AbsListView.startScrollIfNeeded(AbsListView.java:3138)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.widget.AbsListView.onTouchEvent(AbsListView.java:3463)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.View.dispatchTouchEvent(View.java:7127)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2170)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1905)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2176)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1919)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1925)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1379)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.app.Activity.dispatchTouchEvent(Activity.java:2396)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1873)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.View.dispatchPointerEvent(View.java:7307)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3172)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:3117)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:4153)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:4132)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.ViewRootImpl$WindowInputEventReceiver.onInputEvent(ViewRootImpl.java:4224)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:171)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.os.MessageQueue.nativePollOnce(Native Method)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.os.MessageQueue.next(MessageQueue.java:125)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.os.Looper.loop(Looper.java:124)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at android.app.ActivityThread.main(ActivityThread.java:4745)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at java.lang.reflect.Method.invokeNative(Native Method)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at java.lang.reflect.Method.invoke(Method.java:511)
  11-15 00:54:15.635: E/AndroidRuntime(4050):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:
  </code></pre>