Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException

  1. #1
    Junior Member
    Join Date
    Apr 2020
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException

    Hi everyone, I'm a beginner in Java and I'm trying to divide a Jtable into two auther Jtables.Thank you for your help.
     public String Ex(JTable table, JTable tab2, JTable tab3) {
            String message = "Erreur";
            DefaultTableModel modele = new DefaultTableModel();
            tab2.setModel(modele);
            DefaultTableModel modele1 = new DefaultTableModel();
            tab3.setModel(modele1);
            int NumeroLigne = table.getRowCount(), NumeroColonne = table.getColumnCount();
            int t = 0;
            if (NumeroLigne-1 % 2 == 0) {
                t = NumeroLigne / 2;
            }
            else{
                t=(NumeroLigne/2)+1;}
            for (int i = -1; i < t; i++) {
               int r=0;
               r=i+1;
                Object Row[]=new Object[r];
                modele.addRow(Row);
                for (int j = 0; j < NumeroColonne; j++) {
                    if (i ==-1) {
                        modele.addColumn(String.valueOf(table.getColumnName(j)));
                    } else {
                        modele.setValueAt(table.getValueAt(i, j), i, j);
                }
            }}
            for (int i = t; i < NumeroLigne; i++) {
                Object Row1[]=new Object[i];
                modele1.addRow(Row1);
                for (int j = 0; j < NumeroColonne; j++) {
                    if (i ==t) {
                        modele1.addColumn(String.valueOf(table.getColumnName(j)));
                    } else {
                       for(int r=1;r<NumeroLigne;r++){
                        modele1.setValueAt(table.getValueAt(i,j), i, j);
                       }
                    }
                }
            }
            message = "good!!!";
            return message;}
        }

    Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 11 >= 2
    Last edited by lamia; April 15th, 2020 at 07:02 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException

    Also posted here: https://www.dreamincode.net/forums/t...exoutofbounds/

    There error says that an index was used past the end of the array. Look at the line where that exception happened and find the array that was being indexed see why there was an index value past the end of the array.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    lamia (April 15th, 2020)

  4. #3
    Junior Member
    Join Date
    Apr 2020
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException

    from what I understood in your post, in line 34 modele1.setValueAt(table.getValueAt(i,j), i, j);
    I'm asking to put the value table[11][0] in a modele1[11][0] which doesn'texist yet,I have to change the line 27 28 Object Row1[]=new Object[i];
    modele1.addRow(Row1);

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException

    line 34 modele1.setValueAt(table.getValueAt(i,j), i, j);
    What is the size of table and the size of modele1 and what are the values in i and j when that statement is executed?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #5
    Junior Member
    Join Date
    Apr 2020
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Talking Re: Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException

    I find a solution, I just creat model with enough place then stated to fill the model and I changed the pool for with while, add two different counter one for the model and one for the table, I also made some modifications so that it can work in the right way. I just needed to understand the error message, thanks for your help.
    ps: If you want I can post the correct code.
    Last edited by lamia; April 15th, 2020 at 11:38 AM.

Similar Threads

  1. Replies: 8
    Last Post: August 26th, 2014, 03:32 PM
  2. Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    By jimbo62 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 19th, 2013, 06:33 AM
  3. Replies: 2
    Last Post: June 22nd, 2013, 10:30 AM
  4. Replies: 6
    Last Post: March 21st, 2013, 06:43 AM
  5. Replies: 7
    Last Post: August 13th, 2011, 01:22 AM

Tags for this Thread