title: error:- service class has no zero argument constructor
body: <p>I am new to android. I want to use service inside my activity for fetching the JSON data after interval of time. My service class is a inner class of my record class. I made an empty constructor of my service class and tried different approaches but every time I get into an error. Can anyone please guide me on this problem?</p>
  
  <p>record.class</p>
  
  <pre><code>public class record extends Activity{
  .....
  private static String url ="https://podgier-woman.000webhostapp.com/table.php";
  JSONParser jParser = new JSONParser();
  ......
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.record);
      ......
  
      Intent intent = new Intent(record.this,
              BackgroundService.class);
  
      startService(intent);
  
  }
  
  
      class gro extends AsyncTask&lt;String, String, String&gt; {
      protected void onPreExecute() {
          super.onPreExecute();
        ............
          }
      }
  
      protected String doInBackground(String... args) {
          java.util.List&lt;NameValuePair&gt; pr = new ArrayList&lt;NameValuePair&gt;();
  
          JSONObject json = jParser.makeHttpRequest(url, "GET", pr);
  
          try {
              JSONArray code = json.getJSONArray("code");
              Log.d("list :",code.toString());
              for (int i = 0; i &lt; code.length(); i++) {
                  JSONObject c = code.getJSONObject(i);
  
                  asd.add(c.getString("name"));
  
                  // adding each child node to HashMap key =&gt; value
  
                  // adding contact to contact list
                  JSONArray p = null;
              }
              }catch(JSONException e){
  
              }
              return null;
  
      }
  
      protected void onPostExecute(String file_url) {
  
          pDialog.dismiss();
          ..........
  
          Collections.reverse(Arrays.asList(info));
          customList = new CustomList(record.this,info);
          listView = (ListView) findViewById(R.id.listView);
          listView.setAdapter(customList);
  
  
      }
  }
  
  //-----------------------------------------------------------------------------------------------------------------------
  //
  //
  //-----------------------------------------------------------------------------------------------------------------------
  public class BackgroundService extends Service
  {
      public BackgroundService(){
          super();
      }
  
      private static final String TAG = "BackgroundService";
      private ThreadGroup myThreads = new ThreadGroup("ServiceWorker");
  
  
  
      @Override
      public void onCreate() {
          super.onCreate();
          Log.v(TAG, "in onCreate()");
  
      }
  
  
      @Override
      public int onStartCommand(Intent intent, int flags, int startId)
      {
          super.onStartCommand(intent, flags, startId);
          int counter = intent.getExtras().getInt("counter");
  
  
  
          Log.v(TAG, "in onStartCommand(), counter = " + counter +
                  ", startId = " + startId);
  
          new Thread(myThreads, new ServiceWorker(counter), "BackgroundService")
                  .start();
  
  
          return START_NOT_STICKY;
      }
  
  
      class ServiceWorker implements Runnable
      {
          private int counter = -1;
  
          public ServiceWorker(int counter) {
              this.counter = counter;
          }
  
          public void run() {
  
              final String TAG2 = "ServiceWorker:" + Thread.currentThread().getId();
              // do background processing here...
              try {
                  Log.e(TAG2, "sleeping for 5 seconds. counter = " + counter);
  
                  while(true)
                  {
                      Thread.sleep(5000);
                      Log.e("agdghdgdgdrgrdgrdg","dgdgd");
                      new gro().execute();
                  }
              } catch (InterruptedException e) {
                  Log.e(TAG2, "... sleep interrupted");
              }
          }
      }
  
      @Override
      public void onDestroy()
      {
  
      }
      @Override
      public IBinder onBind(Intent intent) {
          Log.v(TAG, "in onBind()");
          return null;
      }
  
  
  }
  
  
  
  }
  </code></pre>
  
  <p>manifest.xml</p>
  
  <pre><code> &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.grover.jsonp"&gt;
  &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity
          android:name=".record"
          android:label="@string/app_name"
          android:theme="@style/AppTheme.NoActionBar"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;service android:name=".record$BackgroundService"/&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p>logcat</p>
  
  <pre><code>   E/AndroidRuntime: FATAL EXCEPTION: main
                Process: com.grover.jsonp, PID: 13046
                java.lang.RuntimeException: Unable to instantiate service com.grover.jsonp.record$BackgroundService: java.lang.InstantiationException: class com.grover.jsonp.record$BackgroundService has no zero argument constructor
                    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2721)
                    at android.app.ActivityThread.access$1800(ActivityThread.java:147)
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368)
                    at android.os.Handler.dispatchMessage(Handler.java:102)
                    at android.os.Looper.loop(Looper.java:135)
                    at android.app.ActivityThread.main(ActivityThread.java:5237)
                    at java.lang.reflect.Method.invoke(Native Method)
                    at java.lang.reflect.Method.invoke(Method.java:372)
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912)
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707)
                 Caused by: java.lang.InstantiationException: class com.grover.jsonp.record$BackgroundService has no zero argument constructor
                    at java.lang.Class.newInstance(Class.java:1563)
                    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2718)
                    at android.app.ActivityThread.access$1800(ActivityThread.java:147) 
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368) 
                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                    at android.os.Looper.loop(Looper.java:135) 
                    at android.app.ActivityThread.main(ActivityThread.java:5237) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at java.lang.reflect.Method.invoke(Method.java:372) 
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707) 
                 Caused by: java.lang.NoSuchMethodException: &lt;init&gt; []
                    at java.lang.Class.getConstructor(Class.java:531)
                    at java.lang.Class.getDeclaredConstructor(Class.java:510)
                    at java.lang.Class.newInstance(Class.java:1561)
                    at android.app.ActivityThread.handleCreateService(ActivityThread.java:2718) 
                    at android.app.ActivityThread.access$1800(ActivityThread.java:147) 
                    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1368) 
                    at android.os.Handler.dispatchMessage(Handler.java:102) 
                    at android.os.Looper.loop(Looper.java:135) 
                    at android.app.ActivityThread.main(ActivityThread.java:5237) 
                    at java.lang.reflect.Method.invoke(Native Method) 
                    at java.lang.reflect.Method.invoke(Method.java:372) 
                    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:912) 
                    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:707) 
  </code></pre>