0

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 to 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)

MrSmith42
  • 9,961
  • 6
  • 38
  • 49
Vishal
  • 2,711
  • 7
  • 33
  • 42
  • You'll likely need to provide the stacktrace for that exception. `InvocationTargetException` merely means that a method that was invoked indirectly (e.g. via reflection) threw a checked exception. So right now the only information that can be gleaned is "something went wrong." ;-) – Andrzej Doyle Nov 09 '10 at 10:27
  • I already have a try-catch surrounding it, it is not showing anything on server console :( – Vishal Nov 09 '10 at 10:30
  • @pvsm - we *need* the stacktrace, do you have a log? Any chance to log the exception? – Andreas Dolk Nov 09 '10 at 10:50
  • InvocationTargetException uses exception-chaining. Important information is in the stack trace. What do you have in your cach block? – MarrLiss Nov 09 '10 at 10:56

1 Answers1

0

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.

Andreas Dolk
  • 113,398
  • 19
  • 180
  • 268