我正在尋找幾天來幫助我,但是我沒有發現任何問題,我真的不知道該怎麼做。在ArrayList中循環不起作用(Get()方法)
這是問題所在......我試圖讓我在這個ArrayList (urlPage)
加入我的循環中的位置我的網址,但我得到這個編譯錯誤:我在一個封閉的範圍定義的局部變量必須爲final或有效的最終。我嘗試了很多東西,但沒有任何作用。
/* Create a loop starting with 0 and ending with 3 to add all the components into the panel */
for (int i = 0; i < 3 ; i++) {
productIconLabel[i] = new JLabel("");
productIconLabel[i].addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
try {
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + urlPage.get(i));
} catch (IOException e) {
e.printStackTrace();
}
}
});
在循環中的代碼繼續(還有就是爲什麼這裏沒有結束支架的),但是這是我有問題的部分。 這是將url
添加到ArrayList
中的功能。
/* Function to receive part of information sent from the form page */
public void radioButtonResult(int productIndexNumber, String productImageAddress, String productName, double productPrice, String url) {
productIconLabel[productIndexNumber].setIcon(new ImageIcon(productImageAddress));
productNameLabel[productIndexNumber].setText(productName);
productPriceLabel[productIndexNumber].setText(Double.toString(productPrice) + " €");
urlPage.add(productIndexNumber, url);
}
唯一的問題是編譯錯誤。爲了做一些測試,我已經改變了我的0,1和2,它的工作。我感謝任何幫助。
代碼中的哪一行會給出錯誤? – AbtPst
是你的getRuntime()。exec的radioButtonResult函數的一部分嗎? – AbtPst
這是一個:Runtime.getRuntime()。exec(「rundll32 url.dll,FileProtocolHandler」+ urlPage.get(i)) –