2017-04-14 36 views
0

這是一段腳本,必須通過TextRecognizer識別相機中的文本,然後搜索文本中的某個單詞。如果該詞出現,系統必須在String found之後保存該詞。無法解析SparseArray的方法<TextBlock>

的問題是,我有這樣的兩個錯誤:

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); 
    } 
    } 

} 

回答

0

你可以找到SparseArray documentation here

正如你看到的,對SparseArray沒有getValue()方法,因此調用一個SparseArraygetValue(int)喜歡你items變量是無效的。

同樣,TextBlock沒有contains(String)方法。撥打items.get(i)將返回TextBlock,因此嘗試撥打上的TextBlock同樣無效。

基於我在你的代碼看,我猜你正在尋找的東西更多類似這樣的,這就要求String的方法:

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); 
    } 
}