Reputation: 4996
I'm trying to access information from the Android CallLog Content Provider, using the code that follows, but it raises an exception java.lang.IllegalArgumentException: Cannot bind argument at index 1 because the index is out of range. The statement has 0 parameters.
// Designates which columns to get back from the content provider
String[] mProjection =
{
CallLog.Calls.NUMBER,
CallLog.Calls.DATE,
CallLog.Calls.DURATION,
CallLog.Calls.TYPE
};
// Defines a string to contain the selection clause
String mSelectionClause = null;
// Initializes an array to contain selection arguments
String[] mSelectionArgs = {""};
Cursor mCursor = getContentResolver().query
(
CallLog.Calls.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
"DATE DESC" // The sort order for the returned rows
);
java.lang.RuntimeException: Unable to start activity ComponentInfo
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:2211)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
at android.app.ActivityThread.access$600(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Upvotes: 1
Views: 427
Reputation:
mSelectionArgs is null at [0]. You need to specifiy it's value at [0], before you use getContentResolver.
// If the word is the empty string, gets everything
if (TextUtils.isEmpty(mSearchString)) {
// 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;
}
http://developer.android.com/guide/topics/providers/content-provider-basics.html
Upvotes: 0
Reputation: 8188
Notice that you're declaring both:
String mSelectionClause = null;
String[] mSelectionArgs = {""};
The first line says that you have no selection arguments but the second line is actually passing ""
, which counts as one argument.
I think that should set mSelectionArgs
to null
or to {}
. Otherwise, the query method will try to insert ""
on an empty clause and that might be what's causing the problem.
Upvotes: 1