Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid SQLite cannot bind argument
    primarykey
    data
    text
    <p>I'm trying to do a simple query of my database, where a unique Identification number is stored for a PendingIntent. To allow me to cancel a notification set by AlarmManager if needed. The insertion of a value works fine, but I am unable to overcome the error:</p> <p>java.lang.IllegalArgumentException: Cannot bind argument at index 1 because the index is out of range. The statement has 0 parameters.</p> <p>Database structure: public class DBAdapter {</p> <pre><code>private static final String TAG = "DBAdapter"; public static final String KEY_ROWID = "_id"; public static final String TASK = "task"; public static final String NOTIFICATION = "notification"; public static final int COL_ROWID = 0; public static final int COL_TASK = 1; public static final int COL_NOTIFICATION = 2; public static final String[] ALL_KEYS = new String[] {KEY_ROWID, TASK, NOTIFICATION}; // DB info: it's name, and the table. public static final String DATABASE_NAME = "TaskDB"; public static final String DATABASE_TABLE = "CurrentTasks"; public static final int DATABASE_VERSION = 3; private static final String DATABASE_CREATE_SQL = "create table " + DATABASE_TABLE + " (" + KEY_ROWID + " integer primary key, " + TASK + " text not null, " + NOTIFICATION + " integer" + ");"; </code></pre> <p>Now I have created a method to extract the notification ID from the database as needed, using the following code:</p> <pre><code> public int getNotifID(long notifID){ String[] x = {ALL_KEYS[2]}; String[]args = new String[]{NOTIFICATION}; String where = NOTIFICATION + "=" + notifID; int y = 0; //String select = "SELECT "+NOTIFICATION+" FROM "+DATABASE_TABLE+" WHERE "+notifID+"="+NOTIFICATION; //Cursor c = db.rawQuery(select,new String[]{}); Cursor c = db.query(true,DATABASE_TABLE,x,Long.toString(notifID),args,null,null,null,null,null); if (c!= null &amp;&amp; c.moveToFirst()){ y = c.getInt(COL_NOTIFICATION); } return y; } </code></pre> <p>As you can see I have attempted to do this both with a rawQuery and a regular query, but with no success.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload