title: Cannot bind argument at index 1 because the index is out of range. The statement has 0 parameters."
body: <p>I am struggling a lot to fix this issue. Can any one please help me to get through this. Please let me know where am I going wrong in my where clause in the query statement. I want to read values from all the columns and then give those to display.</p>
  
  <p>Here is my query code:</p>
  
  <pre><code>public Task getTask1(String id) {
  
  
          db = helper.getReadableDatabase();
  
          String selection = SQLiteHelper.UID;
  
          String[] columns = { SQLiteHelper.UID,
                  SQLiteHelper.TASK_NAME, SQLiteHelper.CONTACTS, SQLiteHelper.DESCRIPTION, SQLiteHelper.REMARKS, SQLiteHelper.DATETIME, SQLiteHelper.ESTIMATED_COMPLETION_TIME,
                  SQLiteHelper.ACTUAL_COMPLETION_TIME, SQLiteHelper.NOTIFY_TIME};
  
          String[] selectionArgs = new String[]{String.valueOf(id)};
  Cursor cursor = db.query(
          SQLiteHelper.TABLE_NAME,
          columns,                
          selection,              
          selectionArgs,          
          null,                   
          null,                   
          null                    
  );
  
  if (cursor != null) {
  
              cursor.moveToNext();
  
  
              task = new Task(
                      cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5),
                      cursor.getString(6), cursor. getString(7), cursor.getString(8));
  
              Log.d("Pana", "The value of Task is" + task);
  
          }
  
  
          return task;
      }
  </code></pre>
  
  <p>Updated method as per the suggestions:</p>
  
  <pre><code>public Task getTask1(String id) {
  
  
          db = helper.getReadableDatabase();
  
          String selection = SQLiteHelper.UID;
  
          String[] columns = { SQLiteHelper.UID,
                  SQLiteHelper.TASK_NAME, SQLiteHelper.CONTACTS, SQLiteHelper.DESCRIPTION, SQLiteHelper.REMARKS, SQLiteHelper.DATETIME, SQLiteHelper.ESTIMATED_COMPLETION_TIME,
                  SQLiteHelper.ACTUAL_COMPLETION_TIME, SQLiteHelper.NOTIFY_TIME};
  
  
          String[] selectionArgs = new String[]{SQLiteHelper.TABLE_NAME, String.valueOf(id)};
  
          Cursor cursor = db.rawQuery("select * from " + SQLiteHelper.TABLE_NAME + " where _id = ?", selectionArgs);
  
  //        if (cursor != null &amp;&amp; cursor.moveToFirst()) {
  //
  //            task = new Task(
  //                    cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5),
  //                    cursor.getString(6), cursor. getString(7), cursor.getString(8));
  //
  //            Log.d("Pana", "The value of Task is" + task);
  //
  //            cursor.close();
  //Don't forget to close your cursor, otherwise you will have a memory leak!
  
          if (cursor != null) {
  
              while (cursor.moveToNext()) {
                  task = new Task(
                          cursor.getString(1), cursor.getString(2), cursor.getString(3), cursor.getString(4), cursor.getString(5),
                          cursor.getString(6), cursor. getString(7), cursor.getString(8));
  
                  Log.d("Pana", "The value of Task is" + task);
              }
  
              cursor.close();
          }
  
  
          return task;
  
  
          }
  </code></pre>
  
  <p>Here is my logcat:</p>
  
  <pre><code> 11:23:06.955    1142-1142/com.ms.t.tms D/AndroidRuntime﹕ Shutting down VM
      --------- beginning of crash
  02-27 11:23:06.970    1142-1142/com.ms.t.tms E/AndroidRuntime﹕ FATAL EXCEPTION: main
      Process: com.ms.t.tms, PID: 1142
      java.lang.RuntimeException: Unable to start activity ComponentInfo{com.ms.t.tms/com.ms.t.tms.EditScreen}: java.lang.IllegalArgumentException: Cannot bind argument at index 1 because the index is out of range.  The statement has 0 parameters.
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
              at android.app.ActivityThread.access$800(ActivityThread.java:144)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5221)
              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:899)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
       Caused by: java.lang.IllegalArgumentException: Cannot bind argument at index 1 because the index is out of range.  The statement has 0 parameters.
              at android.database.sqlite.SQLiteProgram.bind(SQLiteProgram.java:212)
              at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:166)
              at android.database.sqlite.SQLiteProgram.bindAllArgsAsStrings(SQLiteProgram.java:200)
              at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47)
              at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1316)
              at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1163)
              at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1034)
              at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1202)
              at com.ms.t.tms.SQLiteDataBaseAdapter.getTask1(SQLiteDataBaseAdapter.java:143)
              at com.ms.t.tms.EditScreen.onCreate(EditScreen.java:70)
              at android.app.Activity.performCreate(Activity.java:5933)
              at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
              at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
              at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
              at android.app.ActivityThread.access$800(ActivityThread.java:144)
              at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
              at android.os.Handler.dispatchMessage(Handler.java:102)
              at android.os.Looper.loop(Looper.java:135)
              at android.app.ActivityThread.main(ActivityThread.java:5221)
              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:899)
              at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  </code></pre>
  
  <p>I have total of 9 columns in one row including _id as the first column I am trying to query based on _id and I am ending up getting this error. Please help me. I am able to Insert records, Display the records as a list, Read details of the inserted records, but when I try to edit those records I am facing this problem. When I pass null to all the parameters I end up getting the first row of table always. Please provide suggestions. let me know if more information is needed. Thanks in advance.</p>