public float getAccountBalance() { //log.debug("in getAccountBalance");
PostMethod method = new PostMethod(smsServiceUrl);
method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false));
method.setParameter("Username", username);
method.setParameter("PIN", PIN);
method.setParameter("AvailableCredit", "");
String result = new String();
try {
result = doHttpServiceRequest(method);
// log.debug("result is: " + result);
} catch (Exception e) {
// log.warn(e.toString());
}
String[] retArray = result.split(" ");
return Float.valueOf(retArray[1]);
}
这里我得到ArrayIndexOutBoundException。任何人都可以告诉我如何纠正这个异常?ArrayIndexOutOfBoundsException即将到来
请问一个问题,当其可读性格式化你的代码,并告诉我们'result'的值。据推测它不包含空间。 –
使用return Float.valueOf(retArray [0]); –
我会假设'result'可能不包含任何空格,这意味着split将创建一个大小为1的数组(索引0)。 – Dragondraikk