title: Out of memory error in Android swipe images app
body: <p>I am working on a simple android application which has a <code>ViewPager</code> with swiping images. I have static application containing 12 images. When I swipe, the app is getting crashed after the fourth image.</p>
  
  <p>How can I understand the stacktrace and solve this problem?</p>
  
  <blockquote>
  <pre><code>e.. 05-24 21:37:25.718: E/AndroidRuntime(551): FATAL EXCEPTION: main 05-24 21:37:25.718: E/AndroidRuntime(551):
  </code></pre>
    
    <p>java.lang.OutOfMemoryError 05-24 21:37:25.718: E/AndroidRuntime(551):
      at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
    05-24 21:37:25.718: E/AndroidRuntime(551):    at
    android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:483)
    05-24 21:37:25.718: E/AndroidRuntime(551):    at
    android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:351)
    05-24 21:37:25.718: E/AndroidRuntime(551):    at
    android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:773)
    05-24 21:37:25.718: E/AndroidRuntime(551):    at
    android.content.res.Resources.loadDrawable(Resources.java:1935) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.content.res.Resources.getDrawable(Resources.java:664) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.widget.ImageView.resolveUri(ImageView.java:542) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.widget.ImageView.setImageResource(ImageView.java:315) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    com.sqisland.android.swipe_image_viewer.MainActivity$ImagePagerAdapter.instantiateItem(MainActivity.java:72)
    05-24 21:37:25.718: E/AndroidRuntime(551):    at
    android.support.v4.view.ViewPager.addNewItem(ViewPager.java:692) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.support.v4.view.ViewPager.populate(ViewPager.java:875) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.support.v4.view.ViewPager.populate(ViewPager.java:772) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.support.v4.view.ViewPager.completeScroll(ViewPager.java:1539)
    05-24 21:37:25.718: E/AndroidRuntime(551):    at
    android.support.v4.view.ViewPager.computeScroll(ViewPager.java:1422)
    05-24 21:37:25.718: E/AndroidRuntime(551):    at
    android.view.ViewGroup.drawChild(ViewGroup.java:2729) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.view.ViewGroup.drawChild(ViewGroup.java:2885) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.view.ViewGroup.drawChild(ViewGroup.java:2885) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.view.ViewGroup.dispatchDraw(ViewGroup.java:2489) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.view.View.draw(View.java:10981) 05-24 21:37:25.718:
    E/AndroidRuntime(551):    at
    android.widget.FrameLayout.draw(FrameLayout.java:450) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:2126)
    05-24 21:37:25.718: E/AndroidRuntime(551):    at
    android.view.ViewRootImpl.draw(ViewRootImpl.java:2026) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1634)
    05-24 21:37:25.718: E/AndroidRuntime(551):    at
    android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.os.Handler.dispatchMessage(Handler.java:99) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    android.os.Looper.loop(Looper.java:137) 05-24 21:37:25.718:
    E/AndroidRuntime(551):    at
    android.app.ActivityThread.main(ActivityThread.java:4424) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    java.lang.reflect.Method.invokeNative(Native Method) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    java.lang.reflect.Method.invoke(Method.java:511) 05-24 21:37:25.718:
    E/AndroidRuntime(551):    at
    com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    05-24 21:37:25.718: E/AndroidRuntime(551):    at
    com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) 05-24
    21:37:25.718: E/AndroidRuntime(551):  at
    dalvik.system.NativeStart.main(Native Method)</p>
  </blockquote>