我正在尝试将英文词典添加到键盘。到目前为止,我有:
- 从谷歌签出源
- 将 java 文件夹作为现有代码导入 eclipse
- 添加了支持库
我能够运行和构建代码,但是当我选择键盘时它会崩溃(我还没有添加英语或其他字典)。错误信息如下:
FATAL EXCEPTION: InitializeBinaryDictionary
android.content.res.Resources$NotFoundException: File res/raw/main_en.dict from drawable resource ID #0x7f070003
at android.content.res.Resources.openRawResourceFd(Resources.java:1082)
at com.android.inputmethod.latin.BinaryDictionaryGetter.loadFallbackResource(BinaryDictionaryGetter.java:92)
at com.android.inputmethod.latin.BinaryDictionaryGetter.getDictionaryFiles(BinaryDictionaryGetter.java:328)
at com.android.inputmethod.latin.DictionaryFactory.createMainDictionaryFromManager(DictionaryFactory.java:55)
at com.android.inputmethod.latin.DictionaryFactory.createMainDictionaryFromManager(DictionaryFactory.java:83)
at com.android.inputmethod.latin.Suggest$1.run(Suggest.java:115)
Caused by: java.io.FileNotFoundException: This file can not be opened as a file descriptor; it is probably compressed
at android.content.res.AssetManager.openNonAssetFdNative(Native Method)
at android.content.res.AssetManager.openNonAssetFd(AssetManager.java:429)
at android.content.res.Resources.openRawResourceFd(Resources.java:1079)
... 5 more
调用栈中的相关方法如下:
public static ArrayList<AssetFileAddress> getDictionaryFiles(final Locale locale,
final Context context) {
final boolean hasDefaultWordList = DictionaryFactory.isDictionaryAvailable(context, locale);
BinaryDictionaryFileDumper.cacheWordListsFromContentProvider(locale, context,
hasDefaultWordList);
final File[] cachedWordLists = getCachedWordLists(locale.toString(), context);
final String mainDictId = DictionaryInfoUtils.getMainDictId(locale);
final DictPackSettings dictPackSettings = new DictPackSettings(context);
boolean foundMainDict = false;
final ArrayList<AssetFileAddress> fileList = CollectionUtils.newArrayList();
// cachedWordLists may not be null, see doc for getCachedDictionaryList
for (final File f : cachedWordLists) {
final String wordListId = DictionaryInfoUtils.getWordListIdFromFileName(f.getName());
final boolean canUse = f.canRead() && hackCanUseDictionaryFile(locale, f);
if (canUse && DictionaryInfoUtils.isMainWordListId(wordListId)) {
foundMainDict = true;
}
if (!dictPackSettings.isWordListActive(wordListId)) continue;
if (canUse) {
final AssetFileAddress afa = AssetFileAddress.makeFromFileName(f.getPath());
if (null != afa) fileList.add(afa);
} else {
Log.e(TAG, "Found a cached dictionary file but cannot read or use it");
}
}
if (!foundMainDict && dictPackSettings.isWordListActive(mainDictId)) {
final int fallbackResId =
DictionaryInfoUtils.getMainDictionaryResourceId(context.getResources(), locale);
final AssetFileAddress fallbackAsset = loadFallbackResource(context, fallbackResId);
if (null != fallbackAsset) {
fileList.add(fallbackAsset);
}
}
return fileList;
}
public static AssetFileAddress loadFallbackResource(final Context context,
final int fallbackResId) {
String str = context.getApplicationInfo().sourceDir;
AssetFileDescriptor afd = context.getResources().openRawResourceFd(fallbackResId);
if (afd == null) {
Log.e(TAG, "Found the resource but cannot read it. Is it compressed? resId="
+ fallbackResId);
return null;
}
try {
return AssetFileAddress.makeFromFileNameAndOffset(str, afd.getStartOffset(),
afd.getLength());
} finally {
try {
afd.close();
} catch (IOException e) {
// Ignored
}
}
}
我正在使用从 developer.goole.com 下载的 ADT 22
问题是没有字典(甚至没有 EN),所以滑动不起作用。当我打开附加词典时,列表中有“没有可用的词典”消息。
我正在使用 stock 4.3 rom 和 Nexus One Rom cook 4.0.4 在 Samsung Galaxy Nexus 上进行测试
我正在 Ubuntu 12.04.3 LTS 上开发
知道可能是什么问题吗?