gpt4 book ai didi

android - 访问用户字典android

转载 作者:行者123 更新时间:2023-11-29 01:58:51 25 4
gpt4 key购买 nike

您好,这是我从用户词典中获取单词的代码。这是我的代码,但我无法运行它...

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.

这是什么错误..

最佳答案

似乎当 mSelectionClause 为 null 时,mSelectionArgs 也需要为 null。

// If the word is the empty string, gets everything
if (TextUtils.isEmpty(searchWord)) {
// Setting the selection clause to null will return all words
mSelectionClause = null;
mSelectionArgs = null;
} else {
// Constructs a selection clause that matches the word that the user entered
mSelectionClause = UserDictionary.Words.WORD + " = ?";
// Moves the user's input to the selection arguments
mSelectionArgs = new String[] {searchWord};
}

// Does a query against the table and returns a Cursor object
Cursor cursor = 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
null);

关于android - 访问用户字典android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13744792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com