title: Why is .setImageBitmap() not assigning an image to an ImageView object?
body: <p>I've a method that read throughs external storage space for images. I want to store these images in an ImageView ArrayList. To do this I've defined the folder which I want to search through and have created a Bitmap variable that is assigned the image I want to convent to ImageView however the <code>.setImageBitmap(saveImage)</code> doesn't assign to my Imageview object.</p>
  
  <p>Here's the code:</p>
  
  <pre><code> private ArrayList&lt;ImageView&gt; getData() {
  
          ImageView singleImage = null;
          final ArrayList&lt;ImageView&gt; addImage = new ArrayList&lt;&gt;();
          File retrieveImages = new File(Environment.getExternalStoragePublicDirectory(
                  Environment.DIRECTORY_PICTURES), "/WordResolver");
  
          for(File countImages : retrieveImages.listFiles()) {
  
              if(countImages.isFile() &amp;&amp; (countImages.getName().endsWith(".jpg"))) {
  
                  Bitmap saveImage = BitmapFactory.decodeFile(countImages.getAbsolutePath());
                  singleImage.setImageBitmap(saveImage); //Fails here
                  addImage.add(singleImage);
              }
  
          }
  
          return addImage;
      }
  </code></pre>
  
  <p>Here's proof that an image is being read and stored in the BitMap object.</p>
  
  <p><img src="https://imgur.com/rHNPY0F.png" alt="1"></p>
  
  <p>And here's the stacktrace that is throwing a NPE error even though the ImageView should be assigned with an Image.</p>
  
  <blockquote>
    <p>05-20 03:13:38.220 8641-8641/com.example.aaron.wordresolver E/AndroidRuntime: FATAL EXCEPTION: main
                                                                                  Process: com.example.aaron.wordresolver, PID: 8641
                                                                                  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.aaron.wordresolver/com.example.aaron.wordresolver.PictureGallery}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference
                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
                                                                                      at android.app.ActivityThread.-wrap11(ActivityThread.java)
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                      at android.os.Looper.loop(Looper.java:148)
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                                   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.ImageView.setImageBitmap(android.graphics.Bitmap)' on a null object reference
                                                                                      at com.example.aaron.wordresolver.PictureGallery.getData(PictureGallery.java:78)
                                                                                      at com.example.aaron.wordresolver.PictureGallery.onCreate(PictureGallery.java:45)
                                                                                      at android.app.Activity.performCreate(Activity.java:6237)
                                                                                      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1107)
                                                                                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2369)
                                                                                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476) 
                                                                                      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344) 
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                      at android.os.Looper.loop(Looper.java:148) 
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:5417) 
                                                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)  </p>
  </blockquote>