我從PHP獲取結果,並將它們解析爲字符串數組 ParseResults [0]是從數據庫返回的ID。僅針對數組列表中的每個ID執行一次
我想要做的是製作一個消息框,它只顯示一次(直到應用程序重新啓動當然)。
我的代碼看起來像這樣,但我無法弄清楚是什麼阻止它正常工作。
public void ShowNotification() {
try {
ArrayList<String> SearchGNArray = OverblikIntetSvar(Main.BrugerID);
// SearchGNArray = Gets undecoded rows of information from DB
for(int i=0; i<SearchGNArray.size(); i++){
String[] ParseTilArray = ParseResultater(SearchGNArray.get(i));
// ParseToArray = Parse results and decode to useable results
// ParseToArray[0] = the index containing the ID we'd like
// to keep track of, if it already had shown a popup about it
if (SearchPopUpArray.size() == 0) {
// No ID's yet in SearchPopUpArray
// SearchPopUpArray = Where we'd like to store our already shown ID's
SearchPopUpArray.add(ParseTilArray[0]);
// Create Messagebox
}
boolean match = false ;
for(int ii=0; ii<SearchPopUpArray.size(); ii++){
try {
match = SearchPopUpArray.get(ii).equals(ParseTilArray[0]);
} catch (Exception e) {
e.printStackTrace();
}
if(match){
// There is a match
break; // Break to not create a popup
} else {
// No match in MatchPopUpArray
SearchPopUpArray.add(ParseTilArray[0]);
// Create a Messagebox
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
截至目前我有2行,所以應該有兩個ID。有101和102這表明102一次,然後它只是不斷約101
它現在增加了ii ++,但我得到一個死代碼警告......所以它只是通過循環運行一次,我猜? –
根據警告,哪部分代碼死了? – nicopico
for循環包含ii ++ 如果我嘗試System.out.println(ii)匹配後= ... 我得到值(0)回來 - 所以它永遠不會增加 –