The error "java.lang.ArrayIndexOutOfBoundsException: Index 7 out of bounds for length 7" indicates that you are trying to access an index that is outside the bounds of the array. In this case, it seems that the issue is with the line String value = temp.optString(dataKeys[cellNum]);.

To fix this error, you need to make sure that the cellNum variable does not exceed the length of the dataKeys array. You can do this by changing the condition in the for loop from cellNum<displayKeys.length+2 to cellNum<dataKeys.length. Here's the corrected code:

for(cellNum=0;cellNum<dataKeys.length;cellNum++)
{
    String value = temp.optString(dataKeys[cellNum]);
    System.out.println("value============" + value);

    if(dataKeys[cellNum].equals("images"))
    {
        JSONArray images = temp.optJSONArray("images");
        if(images != null)
        {
            for(int j=0; j<images.length(); j++)
            {
                String imageUrl = images.optString(j);
                URL imageUrlObj = new URL(imageUrl);
                InputStream imageStream = imageUrlObj.openStream();
                byte[] byteArray = IOUtils.toByteArray(imageStream);
                int pictureIndex = wb.addPicture(byteArray, Workbook.PICTURE_TYPE_JPEG);
                XSSFClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0, (short) cellNum, i+rowcount, (short) (cellNum+1), i+rowcount+1);
                XSSFPicture picture = patriarch.createPicture(anchor, pictureIndex);
                picture.resize();
            }
        }
    }
    else
    {
        CellUtil.createCell(r, cellNum, value);
    }
}

Make sure to also update any other related parts of your code that may be affected by this change

forint i=0; ilength;i++							r=sheetcreateRowi+rowcount;				rsetHeightshort25615;								int cellNum = 0;				JSONObject temp = new JSONObjectdataoptStringi;				forcellNum=0;cellNumdisplayKeyslength+2

原文地址: https://www.cveoy.top/t/topic/iXde 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录