0

尝试基本的内容提供者示例,但不断出错。android.database.sqlite.SQLiteException: bind or column index out of range,

我是下面的代码

 String[] mSelectionArgs = {""};
 String[] mProjection = {
        UserDictionary.Words._ID,
        UserDictionary.Words.WORD,
        UserDictionary.Words.LOCALE,
        UserDictionary.Words.APP_ID,
        UserDictionary.Words.FREQUENCY
};

 private void getFromDictionary(){
    // If the word is "*" get everything
       if(mSearchString.equalsIgnoreCase("*")){
        // Setting the selection clause to null will return all words
            mSelectionClause = null;
            mSelectionArgs[0] = "";
        }else{
         // Constructs a selection clause that matches the word that the user entered.
            mSelectionClause = UserDictionary.Words.WORD+ " = ?";
            // Moves the user's input string to the selection arguments.
            mSelectionArgs[0]=mSearchString;
        }

    mCursor = mResolver.query(
            UserDictionary.Words.CONTENT_URI,  // The content URI of the words table
            mProjection,                       // The columns to return for each row
            mSelectionClause,           // Either null, or the word the user entered
            mSelectionArgs,             // Either empty, or the string the user entered
            null);                            //  The sort order for the returned rows

下面是Logcat

09-22 15:22:50.545: W/dalvikvm(21939): threadid=1: thread exiting with uncaught exception (group=0x40abe1f8)
09-22 15:22:50.553: E/AndroidRuntime(21939): FATAL EXCEPTION: main
09-22 15:22:50.553: E/AndroidRuntime(21939): android.database.sqlite.SQLiteException: bind or column index out of range: handle 0x2213aa0
09-22 15:22:50.553: E/AndroidRuntime(21939):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:180)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:136)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at android.content.ContentProviderProxy.query(ContentProviderNative.java:362)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at android.content.ContentResolver.query(ContentResolver.java:311)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at com.example.contentprovider.ContentProviderActivity.getFromDictionary(ContentProviderActivity.java:107)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at com.example.contentprovider.ContentProviderActivity.access$1(ContentProviderActivity.java:66)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at com.example.contentprovider.ContentProviderActivity$1.onClick(ContentProviderActivity.java:164)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at android.view.View.performClick(View.java:3526)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at android.view.View$PerformClick.run(View.java:14149)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at android.os.Handler.handleCallback(Handler.java:605)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at android.os.Handler.dispatchMessage(Handler.java:92)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at android.os.Looper.loop(Looper.java:137)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at android.app.ActivityThread.main(ActivityThread.java:4697)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at java.lang.reflect.Method.invokeNative(Native Method)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at java.lang.reflect.Method.invoke(Method.java:511)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
09-22 15:22:50.553: E/AndroidRuntime(21939):    at dalvik.system.NativeStart.main(Native Method)
4

0 回答 0