I have a problem, when i running this code, i found this problem. how to fix it ?
this code
public class kpi {
static String host = "";
public static void main(String[] args) {
host = args[0].toLowerCase();
try {
SimpleDateFormat sdfDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ssZ");
Date now = new Date();
String strDate = sdfDate.format(now);
JSch jsch = new JSch();
Session session = jsch.getSession("hs", args[1], 22);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword("kti365LM");
session.connect();
System.out.println("session connected");
Channel channel = session.openChannel("shell");
OutputStream ops = channel.getOutputStream();
PrintStream ps = new PrintStream(ops, true);
channel.connect();
System.out.println("channel connected");
String prompt = "[local]" + args[0] + "#";
System.out.println(exec(channel, ps, "epg node status", prompt));
String nodeinfo = "";
nodeinfo = exec(channel, ps, "pdc_kpi.pl", prompt);
String[] linenode = nodeinfo.split("\\r?\\n");
String key = "";
JSONObject peerjson = new JSONObject();
peerjson.put("time", strDate.replace(" ", "T"));
peerjson.put("node", args[0]);
for (int i = 6; i 0 && c 0) {`
Pattern p = Pattern.compile("(\\d+(?:\\.\\d+)?)");
Matcher m = p.matcher(fields[j]);
if (m.find()) {
System.out.println(key + ":" + m.group());
peerjson.put(key, Float.parseFloat(m.group().trim()));
c++;
}
}
key = key + fields[j];
c++;
}
if (j > 4 && c == 0)
break;
}
key = "";
}
}
insert(strDate, "nodekpimme", peerjson.toString());
channel.disconnect();
session.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
and this error
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0 at trcrt.kpi.main(kpi.java:24)