1

似乎它应该工作。导入后,我可以在“设置”中的“用户词典”中看到单词。

public static void addWord(Context context, String word, Locale locale) {

        final int COLUMN_COUNT = 5;

        ContentValues values = new ContentValues(COLUMN_COUNT);
        values.put(UserDictionary.Words.WORD, word);
        values.put(UserDictionary.Words.FREQUENCY, DEFAULT_FREQUENCY);
        values.put(UserDictionary.Words.LOCALE, null == locale ? null : locale.toString());
        values.put(UserDictionary.Words.APP_ID, 0); // TODO: Get App UID
        values.put(UserDictionary.Words.SHORTCUT, "");
        resovler.insert(UserDictionary.Words.CONTENT_URI, values);

       }
    }

但是谷歌键盘却被这个错误压垮了(我可以在 logcat 中看到它)

Process: com.google.android.inputmethod.latin, PID: 30183
java.lang.ArrayIndexOutOfBoundsException: length=0; index=0
        at com.android.inputmethod.latin.makedict.FusionDictionary.add(FusionDictionary.java:486)
        at com.android.inputmethod.latin.makedict.FusionDictionary.add(FusionDictionary.java:401)
        at com.android.inputmethod.latin.DictionaryWriter.addUnigramWord(DictionaryWriter.java:72)
        at com.android.inputmethod.latin.ExpandableBinaryDictionary.addWord(ExpandableBinaryDictionary.java:273)
        at com.android.inputmethod.latin.UserBinaryDictionary.addWords(UserBinaryDictionary.java:253)
        at com.android.inputmethod.latin.UserBinaryDictionary.loadDictionaryAsync(UserBinaryDictionary.java:181)
        at com.android.inputmethod.latin.ExpandableBinaryDictionary.writeBinaryDictionary(ExpandableBinaryDictionary.java:542)
        at com.android.inputmethod.latin.ExpandableBinaryDictionary.access$700(ExpandableBinaryDictionary.java:48)
        at com.android.inputmethod.latin.ExpandableBinaryDictionary$12.run(ExpandableBinaryDictionary.java:630)
        at com.android.inputmethod.latin.utils.PrioritizedSerialExecutor$1.run(PrioritizedSerialExecutor.java:70)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:811)

在这次崩溃之后,一切似乎都正常了。拼写检查器可以看到导入的单词。

4

1 回答 1

0

问题显然是以某种方式将空字符串添加到字典中。

于 2014-03-05T16:30:47.510 回答