title: Jasper Reports: JRBeanCollectionDataSource cannot be resolved to a type
body: <p>I'm building a chart in iReports and when I compile in Eclipse I get the following error:  </p>
  
  <pre><code>net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
  1. net.sf.jasperreports.engine.JRBeanCollectionDataSource cannot be resolved to a type
              value = new     net.sf.jasperreports.engine.JRBeanCollectionDataSource(((java.lang.String)field_chartData46xAxis.getValue())); //$JR_EXPR_ID=11$
                          &lt;----------------------------------------------------&gt;
  2. net.sf.jasperreports.engine.JRBeanCollectionDataSource cannot be resolved to a type
              value = new net.sf.jasperreports.engine.JRBeanCollectionDataSource(((java.lang.String)field_chartData46xAxis.getOldValue())); //$JR_EXPR_ID=11$
                          &lt;----------------------------------------------------&gt;
  3. net.sf.jasperreports.engine.JRBeanCollectionDataSource cannot be resolved to a type
              value = new net.sf.jasperreports.engine.JRBeanCollectionDataSource(((java.lang.String)field_chartData46xAxis.getValue())); //$JR_EXPR_ID=11$
                          &lt;----------------------------------------------------&gt;3 errors
  
  at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:204)
  at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:240)
  at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:173)
  at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:448)
  at org.reportprotojava.protosheet.Program.main(Program.java:122)
  </code></pre>
  
  <p>I pass an <strong>ArrayList</strong> of <strong>ProtoReport</strong> (only one right now while I test) to the jasper compiler. The <strong>ProtoReport</strong> class contains a <strong>ChartData</strong> class which in turns has two <strong>ArrayList</strong> of type Double, one for the X-axis and one for the Y-axis.<br>
  The definitions of the <strong>ProtoReport</strong>, <strong>ChartData</strong> classes, and <strong>main program</strong> are as follows(slightly abridged):  </p>
  
  <p><strong>ProtoReport</strong> Class: </p>
  
  <pre><code>package org.reportprotojava.protosheet;
  
  import java.util.ArrayList;
  
  public class ProtoReport {
  
  
  private String outputFileName;
  private String title;
  private String logoLocation;
  private String paragraphText;
  private ArrayList&lt;String&gt; tableData;
  private String picLocation;
  private int[][] graphData;  //TODO decide how to store chart data
  private ChartData chartData;
  private String path;
  
  
  
  
  //default constructor
  public ProtoReport() {
  
      // Initialize object fields
      outputFileName = "PrototypeReport";
      title = "Prototype Report";
      paragraphText = "Default text";
  
      tableData = new ArrayList&lt;String&gt;();
      chartData = new ChartData();
  
      //set path to working directory
      path = System.getProperty("user.dir");
  
      //default to assumed report location 
      //(ie same folder as .jrxml and .jasper files)
      logoLocation = path + "\\reports\\logo.jpg";
      picLocation = path + "\\reports\\pic.jpg";
  
  }
  </code></pre>
  
  <p><strong>ChartData</strong> Class:  </p>
  
  <pre><code>package org.reportprotojava.protosheet;
  
  import java.util.ArrayList;
  
  public class ChartData {
  
  private ArrayList&lt;Double&gt; xAxis;
  private ArrayList&lt;Double&gt; yAxis;
  /**
   * @param xAxis
   * @param yAxis
   */
  
  //default constructor
  public ChartData(){
      xAxis = new ArrayList&lt;Double&gt;();
      yAxis = new ArrayList&lt;Double&gt;();
  }
  
  
  
  //constructor
  public ChartData(ArrayList&lt;Double&gt; xAxis, ArrayList&lt;Double&gt; yAxis) {
      super();
      this.xAxis = xAxis;
      this.yAxis = yAxis;
  }
  </code></pre>
  
  <p><strong>Main Program</strong></p>
  
  <pre><code>public class Program {
  
  /**
   * @param args
   * 
   *Program runs our ProtoReport class and its supporting classes 
   * In the end we will have generated a .pdf from the 
   * previously defined .jrxml file
   */
  
  //Generate some random data for the chart
  public static ArrayList&lt;Double&gt; randomData(int size) {
      ArrayList&lt;Double&gt; arrayList = new ArrayList&lt;Double&gt;();
      double randNumber;
  
      for (int i = 0; i &lt; size; i++) {
          randNumber = Math.random();
          arrayList.add(randNumber);
      }
  
      return arrayList;
  }
  
  public static void main(String[] args) {
  
      ArrayList&lt;ProtoReport&gt; listOfReports = new ArrayList&lt;ProtoReport&gt;();
  
      ProtoReport protoReport1 = new ProtoReport();
      ProtoReport protoReport2 = new ProtoReport();
  
   //Simple Fields and text
      protoReport1.setTitle("Example&lt;br/&gt;Fact Sheet");
  
      protoReport1.setLogoLocation(protoReport1.getPath() + "\\reports\\logo.gif");
  
   ChartData chartData = new ChartData();
      chartData.setYAxis(randomData(20));
      for (Double i = (double) 0; i &lt; chartData.getYAxis().size(); i++) {
          chartData.getXAxis().add(i);
      }
  
          protoReport1.setChartData(chartData);  
   String jrxmlLocation = protoReport1.getPath() 
                      + "\\reports\\ReportPrototype.jrxml";
      String outputFileName = protoReport1.getPath() 
              + "\\reports\\generated\\" + protoReport1.getOutputFileName() + ".pdf";
  
      listOfReports.add(protoReport1);
  
  //and wrap the ArrayList in a JRBeanCollectionDataSource
      JRBeanCollectionDataSource beanBurritoWrap = new JRBeanCollectionDataSource(listOfReports);
  
      //build the jasper report
      JasperReport jasperReport;
      JasperPrint jasperPrint;
      HashMap&lt;String, Object&gt; hashMap = new HashMap&lt;&gt;();
      boolean reportCreated;
  
      try {
  
          jasperReport = JasperCompileManager.compileReport(jrxmlLocation);
          jasperPrint = JasperFillManager.fillReport(jasperReport, hashMap, beanBurritoWrap);
          JasperExportManager.exportReportToPdfFile(jasperPrint, outputFileName);
          reportCreated=true;
      }
      catch (JRException e) {
            e.printStackTrace();
            reportCreated=false;
      }
  
  }
  </code></pre>
  
  <p>I've googled the problem and come up with <a href="http://jasperforge.org/node/531052" rel="nofollow noreferrer">this</a> and <a href="https://stackoverflow.com/questions/8244926/jasper-reposts-cant-compile-an-expression-that-contains-jrbeancollectiondatasou">this</a>, and read the <a href="http://jasperreports.sourceforge.net/sample.reference/datasource/index.html#javabeandatasources" rel="nofollow noreferrer">datasource section on jasper sourceforge</a> but none of these have helped solve the problem, and I've made sure that I've used  </p>
  
  <pre><code> new net.sf.jasperreports.engine.JRBeanCollectionDataSource($F{chartData.xAxis})
  </code></pre>
  
  <p>in my chart data source expression(and updated it when I change field names) and the fields are set to the <strong>List</strong> type in the iReport properties.   </p>
  
  <p>Here is my <strong>.jrxml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="ReportPrototype.jrxml" pageWidth="595" pageHeight="842" columnWidth="495" leftMargin="57" rightMargin="43" topMargin="43" bottomMargin="43" uuid="10825c57-f953-4166-bf03-8ecabe8a8f47"&gt;
  &lt;property name="ireport.zoom" value="0.75"/&gt;
  &lt;property name="ireport.x" value="0"/&gt;
  &lt;property name="ireport.y" value="232"/&gt;
  &lt;subDataset name="ChartData" uuid="fc9ec0af-3e1a-40a7-8eb4-9ad30a266dee"&gt;
      &lt;field name="chartData.xAxis" class="java.lang.String"/&gt;
  &lt;/subDataset&gt;
  &lt;queryString language="SQL"&gt;
      &lt;![CDATA[]]&gt;
  &lt;/queryString&gt;
  &lt;field name="title" class="java.lang.String"/&gt;
  &lt;field name="logoLocation" class="java.lang.String"/&gt;
  &lt;field name="picLocation" class="java.lang.String"/&gt;
  &lt;field name="chartData.xAxis" class="java.lang.String"/&gt;
  &lt;detail&gt;
      &lt;band height="740" splitType="Stretch"&gt;
          &lt;textField isStretchWithOverflow="true" pattern=""&gt;
              &lt;reportElement uuid="519c6bb5-72f9-4c25-8e91-47865ae0c9df" mode="Opaque" x="39" y="75" width="378" height="45" forecolor="#000099"/&gt;
              &lt;textElement textAlignment="Center" verticalAlignment="Middle" markup="html"&gt;
                  &lt;font size="26"/&gt;
              &lt;/textElement&gt;
              &lt;textFieldExpression&gt;&lt;![CDATA[$F{title}]]&gt;&lt;/textFieldExpression&gt;
          &lt;/textField&gt;
          &lt;image onErrorType="Icon"&gt;
              &lt;reportElement uuid="3759a707-32a4-49ef-a9c6-b0ad7136f738" x="216" y="264" width="279" height="246"/&gt;
              &lt;imageExpression&gt;&lt;![CDATA[$F{picLocation}]]&gt;&lt;/imageExpression&gt;
          &lt;/image&gt;
          &lt;image onErrorType="Icon"&gt;
              &lt;reportElement uuid="f989f871-32ea-4f13-ae3f-3f487cde76dd" x="295" y="0" width="200" height="42"/&gt;
              &lt;imageExpression&gt;&lt;![CDATA[$F{logoLocation}]]&gt;&lt;/imageExpression&gt;
          &lt;/image&gt;
          &lt;xyLineChart&gt;
              &lt;chart&gt;
                  &lt;reportElement uuid="ae87fc13-b92e-4a2a-b218-d395343f6028" x="0" y="537" width="495" height="203"/&gt;
                  &lt;chartTitle/&gt;
                  &lt;chartSubtitle/&gt;
                  &lt;chartLegend/&gt;
              &lt;/chart&gt;
              &lt;xyDataset&gt;
                  &lt;dataset&gt;
                      &lt;datasetRun subDataset="ChartData" uuid="de7fb84d-17ea-4e5e-82bf-2015e72e4982"&gt;
                          &lt;dataSourceExpression&gt;&lt;![CDATA[new net.sf.jasperreports.engine.JRBeanCollectionDataSource($F{chartData.xAxis})]]&gt;&lt;/dataSourceExpression&gt;
                      &lt;/datasetRun&gt;
                  &lt;/dataset&gt;
              &lt;/xyDataset&gt;
              &lt;linePlot&gt;
                  &lt;plot/&gt;
              &lt;/linePlot&gt;
          &lt;/xyLineChart&gt;
      &lt;/band&gt;
  &lt;/detail&gt;
  &lt;pageFooter&gt;
      &lt;band height="16"&gt;
          &lt;break&gt;
              &lt;reportElement uuid="0d30dea4-a6af-4e41-b7be-c288f3188dbf" x="0" y="11" width="100" height="1"/&gt;
          &lt;/break&gt;
      &lt;/band&gt;
  &lt;/pageFooter&gt;
  </code></pre>
  
  <p></p>
  
  <p>In iReports I've tried:<br>
  -Creating and naming fields <strong>ProtoReport.ChartData.xAxis</strong> and <strong>ProtoReport.ChartData.yAxis</strong> under Fields <em>and</em> the fields under the <strong>ChartData</strong> source I added<br>
  -Renaming the fields to <strong>ChartData.xAxis</strong> and <strong>ChartData.yAxis</strong><br>
  -Renaming the fields to <strong>chartData.xAxis</strong> and <strong>chartData.yAxis</strong><br>
  -Just using the fields under Field<br>
  -Just using the fields under ChartData - Fields  </p>
  
  <p>All give me an error. Any ideas what I'm doing wrong?  </p>
  
  <p>Additional questions:<br>
  -As it stands my chart will likely only produce the xAxis data points. How can I use the contents of one <strong>ArrayList</strong> for the X-axis and the other for the Y-Axis? ie my <strong>xAxis</strong> and <strong>yAxis</strong> fields in <strong>ChartData</strong> object.<br>
  -The <strong>randomData()</strong>  method I declared before <strong>main</strong> would not run until I declared it <strong><em>static</em></strong>, why is that?</p>
  
  <p><strong>Edit</strong><br>
  To state my question more clearly: How do I name my fields, setup my datasources, and configure my datasets in order to solve this problem?<br>
  I am following the tutorial listed in the comments (sorry for the non-hyper link; as a new user I've used all my hyperlinks already), and making changes to it for my needs, but his data structure is more simple than mine and I'd like to learn how to deal with more complex objects and datasets in jasper reports.</p>