无法解析 SparseArray<TextBlock> 的方法

Cannot resolve method for SparseArray<TextBlock>

这是一段脚本,需要通过TextRecognizer识别摄像头中的文字,然后在文字中搜索某个词。如果该词存在,系统必须在 String found 之后的词中保存。

问题是我有这两个错误:

Cannot resolve method 'contains(java.lang.String)'
Cannot resolve method 'getValue(int)'

我该如何解决这个错误?我还没有找到 SparseArray<TextBlock>.

的任何类似方法
public void receiveDetections(Detector.Detections<TextBlock> detections) {

  String search = "palabra";
  final SparseArray<TextBlock> items = detections.getDetectedItems(); //is the detection of textRecognizer of the camera

  for (int i=0; i<items.size(); ++i) 
  {
    if(items.get(i).contains(search)) 
    {
       String found = items.getValue(i+1);
       Log.i("current lines ", found);
    }
  }

}

您可以找到 SparseArray documentation here.

如您所见,SparseArray 上没有 getValue() 方法,因此在 SparseArray 上调用 getValue(int) 就像您的 items 变量是无效的。

同样,TextBlock 没有 contains(String) 方法。调用 items.get(i) 将 return 变成 TextBlock,因此尝试在 TextBlock 上调用 contains(String) 同样无效。

根据我在你的代码中看到的内容,我猜你正在寻找更像这样的东西,它调用 Stringcontains() 方法:

for (int i=0; i<items.size(); ++i) {]
    TextBlock text = items.get(i)

    // Get the TextBlock's value as a String
    String value = text.getValue()

    // Check if this text block contains the search string
    if(value.contains(search)) {
        String found = items.getValue(i+1);
        Log.i("Found search string " + search + " in block " + value);
    }
}