how to deal with this ArraystoreException element type mismatch?

3.7k views Asked by At

I have a problem with this code:

package com.josuecode.tournament;
import java.util.*;
public class test {

    public static void main(String[] args) {

        ArrayList <Chessplayers> registers = new ArrayList <Chessplayers> ();

        Lists_methods.registrartion(registers,(short) 1);
        Chessplayers[][] round1 = new Chessplayers [2][(int) Math.ceil(registers.size() / 2)];
        round1 = registers.toArray(round1);

        for (int i = 0; i < round1.length; i++) {
            System.out.println(round1[i]);
        }
    }
}

I got this exception in the line 11

"Exception in thread "main" java.lang.ArrayStoreException: arraycopy: element type mismatch: can not cast one of the elements of java.lang.Object[] to the type of the destination array, [Lcom.josuecode.tournament.Chessplayers;"

and I don't know why if both (the ArrayList and the Array) are of the same type.

in the ArrayList are stored Chessplayers class objects and I want to convert that List into java Array.

0

There are 0 answers