java.lang.UnsupportedOperationException: null

user9413194:

Estoy tratando de eliminar celda vacía de Apache-poi. Me sale este error en unmarkedColumns.remove (unmarkedColumns.get (i)): Hay un problema con el método remove. No entiendo why.Can me ayudas?

java.lang.UnsupportedOperationException: null
at java.util.AbstractList.remove(Unknown Source)
at java.util.AbstractList$Itr.remove(Unknown Source)
)    
 Integer[] integers = new Integer[headers.size()];
    Arrays.fill(integers, 0);
    List<Integer> unmarkedColumns = Arrays.asList(integers);
    for (ScoredFormData scoredFormData : scoredFormDatas) {
        Row dataRow = sheet.createRow(++rownum);
        List<Object> rowValues = prepareExportRow(scoredFormData, visitManager, parameters, 
     dynamicDatamanager,
                scoreCriteriaDefinitions);
        for (int i = 0; i < rowValues.size(); i++) {
            if (unmarkedColumns.get(i) != 1 && rowValues.get(i) != null
                    && !rowValues.get(i).equals("")) {
                unmarkedColumns.set(i, 1); 
            }
        }
        populateCells(rowValues, dataRow);
    }

    for (int i = 0; i < unmarkedColumns.size(); i++) {
        if (unmarkedColumns.get(i) == 0) {
            Iterator<Row> rowIterator = sheet.iterator();
            while (rowIterator.hasNext()) {
                Row row = rowIterator.next();
                Boolean changed = false;
                for (int j = i + 1; j < row.getLastCellNum() + 1; j++) {
                    Cell oldCell = row.getCell(j - 1);
                    if (oldCell != null) {
                        row.removeCell(oldCell);
                        changed = true;
                        Cell nextCell = row.getCell(j);
                        if (nextCell != null) {
                            Cell newCell = row.createCell(j - 1, nextCell.getCellType());
                            switch (newCell.getCellType()) {
                            case Cell.CELL_TYPE_BOOLEAN: {
                                newCell.setCellValue(nextCell.getBooleanCellValue());
                                break;}}}}


                if (changed ) {
                    unmarkedColumns.remove(unmarkedColumns.get(i));
                    i = 0;
                }
            }
Al parecer:

Arrays.asList(..) Devuelve una lista con un tamaño fijo, por lo que no puede ampliarlo o reducirlo.

Para solucionarlo, se puede envolver en una ArrayList:

List<Integer> unmarkedColumns = new ArrayList<>(Arrays.asList(integers));

Supongo que te gusta

Origin http://43.154.161.224:23101/article/api/json?id=315716&siteId=1
Recomendado
Clasificación