接入用户词典机器人 [英] access user dictionary android

查看:107
本文介绍了接入用户词典机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的code,以获得用户词典的话。这是我的code,但我不能够运行它...

Hi this is my code to get the words from the user dictionary. this is my code but i am not able to run it...

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.

什么是错误的..

what is the error in this..

推荐答案

好像当mSelectionClause为空,mSelectionArgs需要为空了。

it seems like that when mSelectionClause is null, mSelectionArgs need to be null too.

// 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);

这篇关于接入用户词典机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆