title: Return Callback response from AsyncTask postExecute: Nullpointerexception
body: <p>I've created a component which downloads an Image (in the Android side) and I want to send back size details about that image (to the JS side) of my app. </p>
  
  <p>Now, I can safely say that I can call my component from JS and it will respond back with data but as soon as I add in the <code>Async</code> element to download the image from an URL, read it and respond I get a <code>NullpointerException</code> as soon as I call my <code>callback.invoke("response text");</code></p>
  
  <p>My problematic code is:</p>
  
  <pre><code>public void loadImage(final String url, final Callback onLoadCallback)     {
      ...
      new AsyncTask&lt;String, Void, Void&gt;() {
           @Override
           protected Void doInBackground(String... url) {
               try {
                   theImage = Glide.with(getReactApplicationContext()).load(url[0]).asBitmap().into(-1, -1).get();
               }
               catch ...
  
               return null;
           }
  
           @Override
           protected void onPostExecute(Void dummy) {
               if (null != theImage) {
  
                    onLoadCallback.invoke("Success"); //&lt;== THIS LINE HERE
               }
           }
      }.execute(url);
      ...
  
  
  }
  </code></pre>
  
  <p>Now, I get that it's because I'm trying to return on a sep thread back to the main thread via the callback but I'm not sure how in the heck I'm supposed to get the info I want back to the JS side?! This is my first attempt at a component in RN so be kind! :)</p>
  
  <p>Extra Info - My React module:</p>
  
  <pre><code>var MY_Image = require('NativeModules').MYImage;
  
  var myimage = {
      loadImage(url, onLoad) {
          MY_Image.loadImage(url, onLoad)
      },
  };
  
  module.exports = myimage;
  </code></pre>
  
  <p>Then in my React app view:</p>
  
  <pre><code> ...
   componentDidMount: function() {
      myImage.loadImage('[URL to Image]',onLoad=&gt; {
        console.log('Success: '+onLoad);
      });
  }
  </code></pre>