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