我想嘗試製作一個android應用程序,我接受用戶使用語音識別服務器的輸入。我捕捉如下的ArrayList中的結果:ArrayList.contains(「text」)引發NullPointerException?
matches = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
比賽是全局聲明:
ArrayList<string> matches;
現在我要檢查,如果用戶已經說出一個特定的詞。所以我這樣做:
if(matches.contains("TextToBeDetected")) { }
但線上方拋出一個NullPointerException。
請幫忙。
P.S是的,我是一個Java和Android新手。
ArrayList應該是ArrayList 。在你的getStringArrayListExtra方法中設置了什麼匹配? –
smcg
2012-03-09 16:14:59
@Selvin:我認爲你的意思是OP。對新手來說,這並不意味着什麼。 – 2012-03-09 17:09:22