0
我目前正面臨str.split()
函數的一個奇怪問題。首先here's我的代碼:Android split()在模擬器上工作,但不在設備上
String[] seperated = content.split("<div id=\"results\" style=\"width: 175px; \">");
Log.d("seperated length", "" + seperated.length);
if(seperated.length>1){
Log.d("sep1 t2.", seperated[1]);
String[] sep2 = seperated[1].split("<div id=\"map\" ");
Log.d("sep2 t1", sep2[0]);
String[] sep3 = sep2[0].split("<div class=\"resultLine\">");
result = new String[sep3.length];
for(int i=1; i<sep3.length; i++){
String[] temp = sep3[i].split("class=\"icon1\">");
String[] temp2 = temp[1].split("<br>");
String[] temp3 = temp2[1].split("<br");
String[] temp4 = temp3[0].split("</a>");
result[i-1] = temp2[0] + " " +temp4[0];
Log.d("places", result[i-1]);
}
handler.sendEmptyMessage(0);
} else {
handler.sendEmptyMessage(1);
}
上沒有問題,但第一分割沒有錯誤或任何失敗在設備上生成的結果陣列的仿真器。 字符串內容與仿真器上的內容相同。
你是什麼意思「失敗,沒有錯誤或任何東西」?如果沒有錯誤,你怎麼知道它失敗?有什麼可見的輸出?你期望看到什麼?你的程序是繼續運行還是隻是掛起?你的日誌說什麼? –
重新檢查你的正則表達式。 – Ran
seperated.length在拆分後等於1(它應該等於2),因此我的應用程序進入循環並重新分割字符串。唯一的輸出是我的log.d's。 該表達式在模擬器中工作,所以它應該在設備上工作,不應該嗎? – user1432642