0

this is a piece of a script that has to recognize a text from the camera through TextRecognizer and then search a certain word inside the text. If the word is present, the system has to save in String found the word after.

The problem is that I have this two errors:

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

How can I solve this errors? I haven't found any similar method for 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);
    }
  }

}

1 Answers1

0

You can find the SparseArray documentation here.

As you can see, there is no getValue() method on SparseArray, so calling getValue(int) on a SparseArray like your items variable is not valid.

Similarly, TextBlock doesn't have a contains(String) method. Calling items.get(i) will return a TextBlock, so attempting to call contains(String) on a TextBlock is similarly invalid.

Based on what I see in your code, I'm guessing you are looking for something more like this, which calls String's contains() method:

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);
    }
}
Bryan Herbst
  • 66,602
  • 10
  • 133
  • 120