开发者

Export to Excel from Java - InvocationTargetException

I am stuck at a point while trying to export some data into Excel.

Here is my code

List<String> headers = new ArrayList<String>();
//////////////////////////////////////////////
/// Added some headers in between t开发者_开发百科o the list               
///////////////////////////////////////////////

HSSFCell[] cell = new HSSFCell[headers.size()];

for (int i = 0; i < headersHSSF.length; i++) {  
  cell[i] = excelRow.createCell(i);    
  cell[i].setCellValue(new HSSFRichTextString(headers.get(i)));
}

This code is throwing InvocationTargetException for line

cell[i].setCellValue(new HSSFRichTextString(headers.get(i)));

Can anyone please tell me the reason why is this happening?

(PS: I am calling the code from Flex UI. This is not called from java code)


InvocationTargetException is a checked exception that wraps an exception thrown by an invoked method or constructor.

Could be, that the exception is thrown while creating a HSSFRichTextString class. In this case, I'd look (debug) at the value of headers.get(i) first.

There is a good chance, that you actually have a nested IndexOutOfBoundsException, because the size of the headersHSSF array may be bigger than the size of the headers list.

Change the loop signature to:

for (int i = 0; i < headers.size(); i++) {

and check, if the error is the same, gone or different.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜