在這個類中,我得到了存儲在數據庫中的公共汽車站列表的名稱,並且我想將它們顯示在組合框中。但我得到以下錯誤:數組列表「獲取」問題
GET方法(INT)在ArrayList類型不適用的參數(字符串)
有什麼建議?
// gets the stop names from the database
int[] routeArray = BusStopInfo.getRoutes();
int[] stopIdArray;
ArrayList<String>stopName = new ArrayList<String>();
for(int i = 0; i < routeArray.length; i++) {
stopIdArray = BusStopInfo.getBusStops(i);
for (int j = 0; j < stopIdArray.length; j++) {
stopName.add(BusStopInfo.getFullName(stopIdArray[j]));
}//for
} // for
String[] nameArray = new String[stopName.size()];
nameArray = stopName.toArray(nameArray);
for (int k = 0; k < stopIdArray.length; k++){
stopListDeparture = stopName.get(nameArray[k]);
}
stopListDeparture.setSelectedIndex(0);
setLayout(new BorderLayout());
add(stopListDeparture, BorderLayout.NORTH);
嘗試'字符串str =(字符串)stopName.get(K);' – ryekayo
使用'Map'用於存儲 –
爲更好地幫助更快張貼SSCCE/MCVE,短,可運行的,可編譯的,與硬編碼值在局部變量中使用Swing GUI – mKorbel