【发布时间】:2015-11-28 15:30:21
【问题描述】:
我一直在尝试做这个for循环
for ( int i = 0; i < Main.ipList.length; i++){
JButton btn = new JButton();
btn.setText(Main.ipList[i]);
panel.add(btn);
btn.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e){
Main.refreshSpecificIp(i);
System.out.println("Bu");
}
});
}
Main.refreshSpecificIp(i) 给我一个错误,说“我”必须是最终的或有效地最终的。这是 refreshSpecificIp 函数:
public static void refreshSpecificIp(Integer d){
try
{
InetAddress inet = InetAddress.getByName(ipList[d]);
System.out.println("Sending Ping Request to " + ipList[d]);
boolean status = inet.isReachable(500000); //Timeout = 5000 milli seconds
if (status)
{
System.out.println("Status : " + ipList[d]+ " Host is reachable");
}
else
{
System.out.println("Status " + ipList[d]+ " Host is not reachable");
}
}
catch (UnknownHostException e)
{
System.err.println(ipList[d] + " Host does not exists");
}
catch (IOException e)
{
System.err.println(ipList[d] + " Error in reaching the Host");
}
}
static String[] ipList = {"127.0.0.1", "173.57.51.111", "69.696.69.69"};
如果你能帮助我,我可以继续我的项目。
谢谢。
【问题讨论】:
标签: java arrays function for-loop try-catch