I have a problem with the code below. Compiler says incompatible types, java.lang.object[][] required but found java.lang.object[].
Anyone have an idea why this is? I’ve found some about generics that gives problems here but no solution to my problem.
Object sqlQuery[][] = null;
List<Object[]> sqlLista = new ArrayList<Object[]>();
while (resultSet.next()) {
sqlLista.add(new Object[] { false, resultSet.getString("MMITNO"), null, null, null, null, null } );
}
sqlQuery = sqlLista.toArray();
edit: I have edited the code above as i see i had made a mistake with the dimensions
The problem is that you’re calling the parameterless overload of
toArray(), which returnsObject[]. You can’t assign anObject[]to anObject[][]variable.Now it seems to me that you possibly actually want to make
sqlQueryanObject[][][]instead of anObject[][], so that you get one two-dimensional array per entry in the result set. You’d then have:However, I’d strongly advise you not to go down this route anyway – encapsulate the “result” concept which is currently just
Object[][]in a new type, so you’d have:This will be a lot easier to reason about – even if
Resultonly contains anObject[][].