我正在尝试查看数组的内容,但是在运行它时出现错误消息
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 101
有人知道问题出在哪里吗?
这是我的代码:
public final class KonversiQtoH extends DebitDiberikan{
public KonversiQtoH() throws SQLException{
QBeriPintu1();
}
Connection c = KoneksiDatabase.getKoneksi();
Float[] fine;
public void QBeriPintu1() throws SQLException{
try{
List rowValues = new ArrayList();
Statement s = c.createStatement();
String sql = "SELECT LA40 from tabel_debit";
ResultSet rs = s.executeQuery(sql);
while (rs.next()){
rowValues.add(rs.getFloat("LA40"));
}
rs.close();
s.close();
fine = (Float[]) rowValues.toArray(new Float[rowValues.size()]);
}catch(SQLException e){
System.err.println("QKanan, error");
}
}
public static void main(String[] args) throws SQLException{
KonversiQtoH j = new KonversiQtoH();
j.QBeriPintu1();
for (int i=0; i<=j.fine.length; i++){
int a = i+1;
System.out.println(a+". "+j.fine[i]);
}
}
}
最佳答案
以下行会产生错误:
for (int i=0; i<=j.fine.length; i++) {
用。。。来代替:
for (int i=0; i<j.fine.length; i++) {