title: java.lang.RuntimeException: Unable to instantiate service ... has no zero argument constructor
body: <p>I have a <code>PictureHDFragment</code> in which i use the method <code>Html.fromHtml(String source, Html.ImageGetter imageGetter, Html.TagHandler tagHandler)</code>; i would like the method <code>getDrawable</code> (which is called automatically by <code>Html.fromHtml</code> when it encounters the tag <code>img</code>) to start a thread in order to download the image out of the Fragment and avoid blocking of all application. </p>
  
  <p>Then i have created an external class <code>HttpImageGetter</code> that implements <code>ImageGetter</code> and extend <code>IntentService</code>.</p>
  
  <pre><code>public class HttpImageGetter extends IntentService implements Html.ImageGetter {
  
  private Bitmap bitmap = null;
  private Context context;
  
  public HttpImageGetter(Context context) {
      super("get HTML Image");
      this.context = context;
  }
  
  @Override
  public Drawable getDrawable(String source) {
      //mvc.controller.getDrawable(getContext(), source);
  
      //Context context = getApplicationContext();
      startService(context, source);
      BitmapDrawable bitmapDrawable;
  
      if (bitmap == null)
          bitmapDrawable = null;
      else {
          //bitmapDrawable = bitmapDrawableIterator.next();
          bitmapDrawable = new BitmapDrawable(bitmap);
          bitmapDrawable.setBounds(0, 0, bitmapDrawable.getIntrinsicWidth(), bitmapDrawable.getIntrinsicHeight());
      }
      //BitmapDrawable bitmapDrawableExample = new BitmapDrawable(mvc.model.getHDImage());
      //bitmapDrawableExample.setBounds(0, 0, bitmapDrawableExample.getIntrinsicWidth(), bitmapDrawableExample.getIntrinsicHeight());
  
      return bitmapDrawable/*bitmapDrawableExample*/;
  }
  
  private final static String ACTION = "getImage";
  
  private void startService(Context context, String source){
      Intent intent = new Intent(context/*getApplicationContext()*/, HttpImageGetter.class);
      intent.setAction(ACTION);
      intent.putExtra("source", source);
      context.startService(intent);
  }
  
  @Override
  protected void onHandleIntent(@Nullable Intent intent) {
      String source = intent.getStringExtra("source");
      //Bitmap dr = null;
  
      try {
          URL url = new URL(source);
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();
          conn.setDoInput(true);
          conn.connect();
          InputStream is = conn.getInputStream();
          bitmap = BitmapFactory.decodeStream(is);
          //dr.setBounds(0, 0, dr.getIntrinsicWidth(), dr.getIntrinsicHeight());
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>But this not working and launches <code>RuntimeException</code>, in particular:</p>
  
  <pre><code>java.lang.RuntimeException: Unable to instantiate service com.android.mattia.flickclient.Controller.HttpImageGetter: java.lang.InstantiationException: java.lang.Class&lt;com.android.mattia.flickclient.Controller.HttpImageGetter&gt; has no zero argument constructor
                                                                                      at android.app.ActivityThread.handleCreateService(ActivityThread.java:3446)
                                                                                      at android.app.ActivityThread.-wrap6(ActivityThread.java)
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1725)
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                      at android.os.Looper.loop(Looper.java:154)
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:6692)
                                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
                                                                                   Caused by: java.lang.InstantiationException: java.lang.Class&lt;com.android.mattia.flickclient.Controller.HttpImageGetter&gt; has no zero argument constructor
                                                                                      at java.lang.Class.newInstance(Native Method)
                                                                                      at android.app.ActivityThread.handleCreateService(ActivityThread.java:3443)
                                                                                      at android.app.ActivityThread.-wrap6(ActivityThread.java) 
                                                                                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1725) 
                                                                                      at android.os.Handler.dispatchMessage(Handler.java:102) 
                                                                                      at android.os.Looper.loop(Looper.java:154) 
                                                                                      at android.app.ActivityThread.main(ActivityThread.java:6692) 
                                                                                      at java.lang.reflect.Method.invoke(Native Method) 
                                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468) 
                                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) 
  </code></pre>
  
  <p>So I understand that the problem is the parameter passed to the builder, then I have tryed to removed it and get the context directly in the <code>HttpImageGetter</code> class by the method <code>getApplicationContext</code> but this throw NullPointerException.</p>
  
  <p>How can I resolve this problem?</p>
  
  <p>Thanks </p>