java - 为什么我的 Android 设备 Java 键盘无法识别我说的单词?
问题描述
我正在为 Android 设备开发一个键盘来识别某些单词。我目前有一个来自 Envato Tuts+ 的键盘。在为 Android 开发了一个工作键盘之后,我创建了一个名为WordRecognition.java
. 它包含使该键盘识别单词所需的所有代码。在我的 Android 设备上测试后,我想知道为什么我无法让它工作。我尝试了所有可能的故障排除方法,但没有一个能解决它。我的代码包含几个方法,我想知道是否有人可以告诉我它有什么问题。这是我的以下代码:
package jt.thinktwice.com.thinktwice;
import android.util.Log;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
import static android.content.ContentValues.TAG;
public class WordRecognition {
public static void main(String[] args) throws FileNotFoundException{
// Read the file using whitespace as a delimiter (default)
// so that the input will be split into words
Scanner file = new Scanner(new File("InvalidWord.txt"));
Set<String> InvalidWord = new HashSet<>();
// For each word in the input
while (file.hasNext()) {
// Convert the word to lower case, trim it and insert into the set
// In this step, you will probably want to remove punctuation marks
InvalidWord.add(file.next().trim().toLowerCase());
}
System.out.println("Enter a word to search for: ");
Scanner input = new Scanner(System.in);
// Also convert the input to lowercase
String search = input.next().toLowerCase();
// Check if the set contains the search string
if (InvalidWord.contains(search)) {
System.out.println("Invalid Word Said!");
Log.i(TAG, "main: Invalid Word Said ");
} else System.out.println("Valid Word Said!");
Log.i(TAG, "main: Invalid Word Said ");
}
在上面的代码中,我Java Scanner
在 InvalidWord.txt 文件中搜索单词。我的问题有几种不同的情况,但我认为主要是我的 InvalidWord.txt 文件位于错误的位置。它位于资产文件夹中。如果这不是问题,有人可以修改我的代码来修复它吗?
解决方案
推荐阅读
- c# - 在 EF Core Linq GroupBy 语句中使用前导零格式化日期
- mongodb - 如何在 mongo golang 驱动程序中使用聚合 $facet 查询
- angular - 有没有办法使用变量值在 apollo 客户端上缓存查询结果?
- c# - Protobuf字符串到可读字符串?
- excel - STDEVIFS:就像 AVERAGEIFS,如何?
- php - 复杂的继承变量合并
- javascript - 使网格及其项目调整大小以适合容器
- javascript - 在 Vue.js 组件中创建 Monaco Editor 的实例
- linux - 在 SH 文件中运行时找不到命令
- python - 在装饰器的末尾修剪零元素