嗨,這是我的代碼來從用戶字典中獲取單詞。這是我的代碼,但我不能夠運行它...訪問用戶字典android
private String getwordlist() {
String[] mSelectionArgs={""};
String[] mProjection ={UserDictionary.Words._ID, UserDictionary.Words.WORD, UserDictionary.Words.FREQUENCY};
String mSelectionClause = null;
String mSortOrder = null;
mCursor = getContentResolver().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
mSortOrder); // The sort order for the returned rows
if (mCursor.moveToFirst()) {
do {
String id = mCursor.getString(mCursor.getColumnIndex(UserDictionary.Words._ID));
String word = mCursor.getString(mCursor.getColumnIndex(UserDictionary.Words.WORD));
String freq= mCursor.getString(mCursor.getColumnIndex(UserDictionary.Words.FREQUENCY));
str=str+" id: "+id+" word: "+" frequency: "+freq+"\n";
System.out.println(str);
} while(mCursor.moveToNext());
return str;
}
return null;
}
我收到錯誤
12-06 18:49:58.586: E/AndroidRuntime(17174): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.ScrollView}: java.lang.IllegalArgumentException: Cannot bind argument at index 1 because the index is out of range. The statement has 0 parameters.
什麼是這個錯誤..
這對我有用:) – user2065636
你爲什麼這麼說?如果您查看Content Provider Basics的開發人員文檔,您將看到他們的示例「構建查詢」。它與你所說的相矛盾:http://developer.android.com/guide/topics/providers/content-provider-basics.html#AltForms –