You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "Richard C. Baus" <rb...@mtcsc.com> on 2009/04/23 17:03:10 UTC

ClassCastException: HSSFWorkbook to Workbook in 3.5 Beta 5

I am getting the following runtime exception:

     [java] Exception in thread "AWT-EventQueue-0"
java.lang.ClassCastException: org.apache.poi.hssf.usermodel.HSSFWorkbook
cannot be cast to org.apache.poi.ss.usermodel.Workbook
     [java]     at 
....ExportToExcelAction.getXLSWorkBook(ExportToExcelAction.java:153)

The code is this:

    private Workbook getXLSWorkBook() {        Workbook genericWorkbook =
null;        HSSFWorkbook wb = new HSSFWorkbook();
genericWorkbook = (Workbook)wb;        return genericWorkbook;    }

If I do this same thing for an XSSFWorkbook, it works fine. I have tried any
number of different ways to do this cast for HSSFWorkbook. Either the
compiler flags it or I get a runtime exception ­ no matter what, I haven¹t
figured out how to do this. This should work like XSSFWorkbook since they
both implement the Workbook interface.

I am using 3.5 Beta 5.

Any thoughts? Is this a bug?



> Carvel Baus
> Software Engineer, MTCSC
> 843-218-6197
> rbaus@mtcsc.com
> 
> "The significant problems we face cannot be solved at the same level of
> thinking we were at when we created them."
>   --  Albert Einstein
> 



    

Important Notice: This email message and any attachments may contain information and/or trade secrets that are private, and are meant to be delivered solely for the use of the intended recipient(s). If you are not the intended recipient, please do not read, copy, use, forward or disclose the contents of this communication to others. Interception of e-mail is a crime under the Electronic Communications Privacy Act, 18 U.S.C. 2510-2522 and 2701-2709. If you have received this email in error, please immediately notify us by return email or by telephone at [703-221-0200 Ext 51119] and promptly delete this message. Thank You.



Re: ClassCastException: HSSFWorkbook to Workbook in 3.5 Beta 5

Posted by "Richard C. Baus" <rb...@mtcsc.com>.
Yes, that was it - removed it in Eclipse but it was still in the lib
directory where an ant task was doing the compile.

Thanks,
Carvel


On 4/23/09 11:13 AM, "Nick Burch" <ni...@torchbox.com> wrote:

> On Thu, 23 Apr 2009, Richard C. Baus wrote:
>> I am getting the following runtime exception:
>> 
>>      [java] Exception in thread "AWT-EventQueue-0"
>> java.lang.ClassCastException: org.apache.poi.hssf.usermodel.HSSFWorkbook
>> cannot be cast to org.apache.poi.ss.usermodel.Workbook
> 
> Pretty sure you've got an older version of poi on your runtime classpath.
> Please use the example code in the FAQ on the site to verify where your
> HSSFWorkbook is coming from (I bet its an older poi jar version)
> 
> Nick
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
> For additional commands, e-mail: user-help@poi.apache.org


> Carvel Baus
> Software Engineer, MTCSC
> 843-218-6197
> rbaus@mtcsc.com
> 
> "The significant problems we face cannot be solved at the same level of
> thinking we were at when we created them."
>   --  Albert Einstein
> 




Important Notice: This email message and any attachments may contain information and/or trade secrets that are private, and are meant to be delivered solely for the use of the intended recipient(s). If you are not the intended recipient, please do not read, copy, use, forward or disclose the contents of this communication to others. Interception of e-mail is a crime under the Electronic Communications Privacy Act, 18 U.S.C. 2510-2522 and 2701-2709. If you have received this email in error, please immediately notify us by return email or by telephone at [703-221-0200 Ext 51119] and promptly delete this message. Thank You.



Re: ClassCastException: HSSFWorkbook to Workbook in 3.5 Beta 5

Posted by Nick Burch <ni...@torchbox.com>.
On Thu, 23 Apr 2009, Richard C. Baus wrote:
> I am getting the following runtime exception:
> 
>      [java] Exception in thread "AWT-EventQueue-0"
> java.lang.ClassCastException: org.apache.poi.hssf.usermodel.HSSFWorkbook
> cannot be cast to org.apache.poi.ss.usermodel.Workbook

Pretty sure you've got an older version of poi on your runtime classpath. 
Please use the example code in the FAQ on the site to verify where your 
HSSFWorkbook is coming from (I bet its an older poi jar version)

Nick