net.sqlcipher.database.SQLiteException:绑定或列索引超出范围:handle 0x7bf058da88

时间:2017-06-01 13:25:55

标签: android android-contentprovider android-cursorloader

我的内容提供商存在问题。我在我的一个活动中使用内容提供程序,使用CursorLoader和适配器来显示列表。

当且仅当我没有在CursorLoader构造函数中指定selection和selectionArgs参数时,该列表显示了Task表的内容。

我已尝试为选择和选择args传入空值,这将返回整个表的内容。我想要做的是根据C_TASK_CALLID列选择表的完整投影并传入一个callID。

所以我想做的是返回一个基于某些sql的游标,如下所示:

select * from table TASK where C_TASK_CALLID = callID;

有谁能告诉我为什么我会得到以下错误?

我查看了以下SO帖子,但它表明选择和selectionArgs之间存在不匹配。就我而言,这不是真的,因为我只传递了一个参数。

link

我收到以下错误:

06-01 14:05:56.631 32037-32037/com.carefreegroup.rr3 E/ViewCompletedTasksActivity: about to create CursorLoader.....LoginValidate.C_TASK_CALLID = taskcallid callID =  d5f5482f-b240-4eb6-8be1-489a8d75af9b
06-01 14:05:56.636 32037-2691/com.carefreegroup.rr3 E/RR3ContentProvider: inside RR3ContentProvider query method
06-01 14:05:56.636 32037-2691/com.carefreegroup.rr3 E/LoginValidate: NfcScannerApplication.getSecretKey() = 12345
06-01 14:05:56.636 32037-2691/com.carefreegroup.rr3 E/RR3ContentProvider: CASE TASKS
06-01 14:05:56.636 32037-2691/com.carefreegroup.rr3 E/RR3ContentProvider: About to do the query method in content provider
06-01 14:05:56.645 32037-2691/com.carefreegroup.rr3 E/CustomExceptionHandler: stack = java.lang.RuntimeException: An error occurred while executing doInBackground()
                                                                                  at android.os.AsyncTask$3.done(AsyncTask.java:318)
                                                                                  at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
                                                                                  at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
                                                                                  at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                                                                                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
                                                                                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
                                                                                  at java.lang.Thread.run(Thread.java:762)
                                                                               Caused by: net.sqlcipher.database.SQLiteException: bind or column index out of range: handle 0x7bf058da88
                                                                                  at net.sqlcipher.database.SQLiteProgram.native_bind_string(Native Method)
                                                                                  at net.sqlcipher.database.SQLiteProgram.bindString(SQLiteProgram.java:245)
                                                                                  at net.sqlcipher.database.SQLiteQuery.bindString(SQLiteQuery.java:183)
                                                                                  at net.sqlcipher.database.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:48)
                                                                                  at net.sqlcipher.database.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1820)
                                                                                  at net.sqlcipher.database.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:330)
                                                                                  at net.sqlcipher.database.SQLiteQueryBuilder.query(SQLiteQueryBuilder.java:280)
                                                                                  at com.carefreegroup.rr3.RR3ContentProvider.query(RR3ContentProvider.java:396)
                                                                                  at com.carefreegroup.rr3.RR3ContentProvider.query(RR3ContentProvider.java:23)
                                                                                  at android.content.ContentProvider.query(ContentProvider.java:1027)
                                                                                  at android.content.ContentProvider$Transport.query(ContentProvider.java:243)
                                                                                  at android.content.ContentResolver.query(ContentResolver.java:536)
                                                                                  at android.content.CursorLoader.loadInBackground(CursorLoader.java:64)
                                                                                  at android.content.CursorLoader.loadInBackground(CursorLoader.java:56)
                                                                                  at android.content.AsyncTaskLoader.onLoadInBackground(AsyncTaskLoader.java:312)
                                                                                  at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:69)
                                                                                  at android.content.AsyncTaskLoader$LoadTask.doInBackground(AsyncTaskLoader.java:66)
                                                                                  at android.os.AsyncTask$2.call(AsyncTask.java:304)
                                                                                  at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
                                                                                  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
                                                                                  at java.lang.Thread.run(Thread.java:762) 

以下是我的任务表:

public static final String C_ID_TASK_QUEST_COMM = BaseColumns._ID;
    public static final String C_TASK_QUEST_COMM_QUESTSION = "taskquestcommquestion";
    public static final String C_TASK_QUEST_COMM_COMMENTS = "taskquestcommcomments";
    public static final String C_TASK_QUEST_ID = "taskquestid";
    public static final String C_TASK_QUEST_TYPE = "taskquesttype";
    public static final String C_TASK_CALLID = "taskcallid";
    public static final String C_TASK_SENT_TO_SERVER = "tasksenttoserver";
    public static final String C_TASK_VALUE = "taskvalue";

下面的

是我的Activity中的CursorLoader构造函数:

@Override
    public Loader<Cursor> onCreateLoader(int id, Bundle args) {

        Log.e(TAG, "inside3 onCreateLoader in ViewCompletedTasksActivityAsync");




        String[] projection = { LoginValidate.C_ID_TASK_QUEST_COMM, LoginValidate.C_TASK_QUEST_COMM_QUESTSION, LoginValidate.C_TASK_QUEST_COMM_COMMENTS,
                LoginValidate.C_TASK_QUEST_ID,
                LoginValidate.C_TASK_QUEST_TYPE , LoginValidate.C_TASK_CALLID, LoginValidate.C_TASK_SENT_TO_SERVER, LoginValidate.C_TASK_VALUE};



        String [] selectionArgs = {callID};


        Log.e(TAG, "about to create CursorLoader.....LoginValidate.C_TASK_CALLID = " + LoginValidate.C_TASK_CALLID + " callID = " + callID);

        cursorLoader = new CursorLoader(this, RR3ContentProvider.CONTENT_URI_TASKS, projection, LoginValidate.C_TASK_CALLID, selectionArgs , null);

        return cursorLoader;
    }

以下是我的contentProvider:

public class RR3ContentProvider extends ContentProvider {

   private static final String TAG = RR3ContentProvider.class.getSimpleName();
   NfcScannerApplication nfcAppObj; 

   static final String PROVIDER_NAME = "com.xxxxx.xxx.ContentProvider";





    static final String URLTASKS = "content://" + PROVIDER_NAME + "/tasks";
    static final Uri CONTENT_URI_TASKS = Uri.parse(URLTASKS);


    static final String _ID_TASKS = "_id";
    static final String TASK_QUESTION = "taskquestcommquestion";


    static final String TABLETASKS = "tabletaskquestion";

    private static HashMap<String, String> TASK_PROJECTION_MAP;

    static final int TASKS = 9;
    static final int TASK_ID = 10;





   static final UriMatcher uriMatcher;
   static{
      uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);

       uriMatcher.addURI(PROVIDER_NAME, "tasks", TASKS);
       uriMatcher.addURI(PROVIDER_NAME, "tasks/#", TASK_ID);
   }

   /**
    * Database specific constant declarations
    */
   private SQLiteDatabase db;


   @Override
   public boolean onCreate() {


       Context applicationContext = getContext().getApplicationContext();
       nfcAppObj = getRealApplication(applicationContext);



      Log.e(TAG, "inside RR3ContentProvider onCreate");
      return (nfcAppObj == null)? false:true;
   }



   @Override
   public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {

       Log.e(TAG, "inside RR3ContentProvider query method");


       db = nfcAppObj.getDb();

      SQLiteQueryBuilder qb = new SQLiteQueryBuilder();


      switch (uriMatcher.match(uri)) {








          case TASKS:
              Log.e(TAG, "CASE TASKS");
              qb.setTables(TABLETASKS);
              qb.setProjectionMap(TASK_PROJECTION_MAP);



              /*if (sortOrder == null || sortOrder == ""){

                  sortOrder = LOG_CREATED_TIME + " DESC";
              }*/

              break;

          case TASK_ID:
              Log.e(TAG, "CASE TASK_ID");
              qb.setTables(TABLETASKS);
              qb.appendWhere( _ID_TASKS + "=" + uri.getPathSegments().get(1));

              /*if (sortOrder == null || sortOrder == ""){

                  sortOrder = LOG_CREATED_TIME + " DESC";
              }*/

              break;

      default:

         throw new IllegalArgumentException("Unknown URI " + uri);
      }




      Log.e(TAG, "About to do the query method in content provider");

      Cursor c = qb.query(db,   projection, selection, selectionArgs,
                          null, null, sortOrder);
      /** 
       * register to watch a content URI for changes
       */
      c.setNotificationUri(getContext().getContentResolver(), uri);

      return c;

   }//end of query












   @Override
   public String getType(Uri uri) {
      switch (uriMatcher.match(uri)){
      /**
       * Get all  records 
       */


          case TASKS:
              return "vnd.android.cursor.dir/vnd.example.tasks";
          /**
           * Get a particular record
           */
          case TASK_ID:
              return "vnd.android.cursor.item/vnd.example.tasks";
      default:
         throw new IllegalArgumentException("Unsupported URI: " + uri);
      }
   }
}

1 个答案:

答案 0 :(得分:0)

您的SQL查询错误! “select * from table TASK where C_TASK_CALLID = callID;”冗余的“表”。更改“从TASK中选择*,其中C_TASK_CALLID = callID;”