title: Service "has no zero argument constructor", But it does. What to do? Make class static?
body: <p>I have an Android app that works fine, but I want it to be able to run in the background and continue running even when it doesn't have focus.</p>
  
  <p><code>QueryDB</code> (see below) extends <code>AsyncTask</code> in the current version of the app. I've been advised to use a <code>Service</code> (or <code>IntentSerivce</code>) to accomplish the above goal.</p>
  
  <p>So I changed <code>QueryDB</code> to extend <code>IntentService</code> for starters.</p>
  
  <p>Doing so caused this exception in Android Studio 1.5.1:</p>
  
  <pre><code>04-29 12:02:45.544 1523-1523/com.dslomer64.wordyhelperton E/AndroidRuntime: 
  FATAL EXCEPTION: main
  
      Process: com.dslomer64.wordyhelperton, PID: 1523
  
      java.lang.RuntimeException: Unable to instantiate service 
      com.dslomer64.wordyhelperton.DatabaseConnector$QueryDB: 
                                                     ^^^^^^^
      java.lang.InstantiationException: 
      java.lang.Class&lt;com.dslomer64.wordyhelperton.DatabaseConnector$QueryDB&gt; 
      has no zero argument constructor
  
              at android.app.ActivityThread.handleCreateService(ActivityThread.java:2880)
              at android.app.ActivityThread.access$1900(ActivityThread.java:157)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1439)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:148)
              at android.app.ActivityThread.main(ActivityThread.java:5551)
              at java.lang.reflect.Method.invoke(Native Method)
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
  
  
   Caused by: java.lang.InstantiationException:
   java.lang.Class&lt;com.dslomer64.wordyhelperton.DatabaseConnector$QueryDB&gt; 
                                                                  ^^^^^^^
       has no zero argument constructor
  
  
              at java.lang.Class.newInstance(Native Method)
              at android.app.ActivityThread.handleCreateService(ActivityThread.java:2877)
              at android.app.ActivityThread.access$1900(ActivityThread.java:157) 
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1439) 
              at android.os.Handler.dispatchMessage(Handler.java:102) 
              at android.os.Looper.loop(Looper.java:148) 
              at android.app.ActivityThread.main(ActivityThread.java:5551) 
              at java.lang.reflect.Method.invoke(Native Method) 
              at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730) 
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620) 
  </code></pre>
  
  <p>Here's the start of QueryDB that caused the error:</p>
  
  <pre><code> public class QueryDB extends IntentService
    {
      public QueryDB()
      {
        super("QueryDB");
      }
  
      public QueryDB(String name)
      {
        super(name);
      }
  </code></pre>
  
  <p><code>QueryDB</code>, which is linked to the error, is a class within <code>DatabaseConnector</code>. </p>
  
  <p>After considerable Googling and following SO links, I found an SO Answer that suggested making class <code>QueryDB</code> <code>static</code>. Doing so got rid of the above error.</p>
  
  <p>But since changing <code>QueryDB</code> from <code>AsyncTask</code> to <code>IntentService</code> is the only change I've made, I'm getting another error that I think I know what to do about, but I have a long way to go and I don't want this change to come back and bite me.</p>
  
  <p>After <code>QueryDB</code> executes and terminates, it will be executed again after further user input.</p>
  
  <p>Is making class <code>QueryDB</code> <code>static</code> perfectly safe and a good idea as long as I only need to have one instance of it executing at any time? I think it has to be an inner class of <code>DatabaseConnector</code>.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Per suggestion in first comment, <a href="https://stackoverflow.com/q/253492/2737933">this</a> will prove to be interesting reading.</p>
  
  <p>So may <a href="https://stackoverflow.com/a/10851904/2737933">this</a>.</p>