Hitachi Vantara Pentaho Community Forums
Results 1 to 3 of 3

Thread: ClassCastException when ItemFactory.createStringElement

  1. #1

    Default ClassCastException when ItemFactory.createStringElement

    Hi,

    I am trying to create Report Definition following the 0.8.3d Reference Guide.

    I keep getting ClassCastException when I create TextElement using ItemFactory.createStringElement (see below). The code is very similar to that in the Reference Guide, but somehow the error persists. Is there anyone who knows why this is happening?

    Thanks a lot in advance. I am using Sun J2SE 1.4.0_01 on Windows machine.

    Code:
    public com.jrefinery.report.JFreeReport createReportDefinition(String reportName, Object[] columnNames, double width, double height) {
            report = new JFreeReport();
            report.setName(reportName);
            
            for&#40;int i = 0; i < columnNames.length; i++&#41;&#123;
                TextElement te = ItemFactory.createStringElement&#40;
                    "Element" + &#40;String&#41;columnNames&#91;i&#93;,
                    new Rectangle2D.Double&#40;width*i/columnNames.length, 0.0, width/columnNames.length, height&#41;,
                    Color.black,
                    ElementAlignment.LEFT.getOldAlignment&#40;&#41;,
                    ElementAlignment.MIDDLE.getOldAlignment&#40;&#41;,
                    null, // font
                    "-", // null string
                    &#40;String&#41;columnNames&#91;i&#93;
                &#41;;
                report.getItemBand&#40;&#41;.addElement&#40;te&#41;;
            &#125;
    
            return report;

  2. #2
    Join Date
    Mar 2003
    Posts
    8,085

    Default

    Hi,

    the only place I can see where the ClassCastException could occur, is the cast from the Object[] columnNames into a string.

    If you expect that the column names are all strings (as it should be), then use a String[] and remove the casting.

    Have more fun,
    said Thomas

  3. #3

    Default

    Thanks, Thomas. It was the problem with Object []....doh.....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Privacy Policy | Legal Notices | Safe Harbor Privacy Policy

Copyright © 2005 - 2019 Hitachi Vantara Corporation. All Rights Reserved.