簡體   English   中英

JTable中的數組索引超出范圍異常

[英]Array Index Out Of Bounds Exception in JTable

    public int getSum(){
        int sum=0;

        for(int i=1; i <= sqlite_master.getRowCount(); i++)
        {
            sum=sum+Integer.parseInt((String) sqlite_master.getValueAt(i, 2));      
        }
        return sum;
    }

編寫代碼是為了獲得2列表中某一列的總和,其中一列字符串和其他數字

錯誤是

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 2 >= 2
at java.util.Vector.elementAt(Vector.java:474)

請提供一些解決方案以解決問題

這應該更好。 索引從0開始,直到行數減1。

public int getSum(){
        int sum=0;

        for(int i=0; i < sqlite_master.getRowCount(); i++)
        {
            sum=sum+Integer.parseInt((String) sqlite_master.getValueAt(i, 2));      
        }
        return sum;
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM