title: What's the source of this NullPointerException
body: <p>OK, so I'm writing an Android app, and am trying to download a Bitmap and set it as an ImageView. The code is below for the relevant parts:</p>
  
  <pre><code>    private class GetContactInfo extends AsyncTask&lt;String, Void, ContactInfo[]&gt; {
  
      @Override
      protected ContactInfo[] doInBackground(String... url) {
          // Instantiate what is needed
          URL json = null;
  
          //Set the JSON URL
          try {
              json = new URL(url[0]);
          } catch (MalformedURLException e1) {
              e1.printStackTrace();
          }
  
          // Use Jackson library to read out the data from the contacts page
          try {
              contacts = mapper.readValue(json, ContactInfo[].class);
          } catch (JsonParseException e) {
              e.printStackTrace();
          } catch (JsonMappingException e) {
              e.printStackTrace();
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          //Add everything into the bitmap ArrayList
          for (int i = 0; i &lt; contacts.length; i++) {
              String imageURL = contacts[i].getSmallImageURL();
  
              // Download the Bitmap and add it to the ArrayList
              try {
                  bitmap.add(downloadBitmap(imageURL));
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
  
          // Return statement
          return contacts;
      }
  </code></pre>
  
  <hr>
  
  <pre><code>public Bitmap downloadBitmap(String imageURL) throws IOException {
  
      URL url = new URL(imageURL);
      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.setDoInput(true);
      connection.connect();
      InputStream stream = connection.getInputStream();
      Bitmap bitmap = BitmapFactory.decodeStream(stream);
      if (bitmap == null) {
          Log.e("Null", "Bitmap null");
      }
  
      return bitmap;
  }
  </code></pre>
  
  <p>The log never catches that bitmap is null, or at least it doesn't show it (I see in the stack trace that there are 4 more errors, but they never show up and I'm not sure how to expand it to show the other errors.)</p>
  
  <p>The NullPointerException comes at the <code>bitmap.add(downloadBitmap(imageURL));</code> line. So somehow my <code>downloadBitmap</code> function is returning a null result. Any ideas?</p>
  
  <p>Edit: I'm not sure if this matters, but the images in the URLs are .jpeg files.</p>
  
  <p>Edit 2: Put this in the comments so I will edit it into my post as well, bitmap is declared as a Global Variable like so <code>ArrayList&lt;Bitmap&gt; bitmap;</code> This is so I can later use it in my onPostExecute method.</p>