Я создаю JasperReport, который создает более 2 записей с помощью HashMap, однако он создает только 2 записи в источнике данных и, если он превышен, дает arrayoutofboundException 2.
список проверенных и пытались массивов, чтобы поместить значения name dob возраста ви затем получить данные в поля, однако он отображает только 2 записи и останавливается на второй записи, а затем выдает массив из привязанного исключения для hashMap
public class Implementation implements JRDataSource{
static List<Records> items = new ArrayList<Records>();
private static final Integer[] lotNum = {33301141,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143,33301143 };
private static final Integer[] level= {1,3,3,3,3,3,33,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2};
private static final double[] mean= {4.49,457.04,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49,4.49};
private static final double[] SD= {0.30,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58,22.58};
private static final double[] CV= {6.79,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,4.94,3.40,3.50};
private static final Integer[] N= {54,53,54,66,77,88,87,65,45,34,34,23,45,67,78,98,43,23,12,34,67,87,43,23,56,12,33,45,21,22,32};
private static final double[] mean2= {3.92,465.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95,5.95};
private static final double[] SD2= {0.35,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11,31.11};
private static final double[] CV2= {9.04,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68,6.68};
private static final Integer[] N2= {333,340,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40,40};
private static final String[] department = {"GENERAL"," "};
private static final String[] instruementArray = {"ARCHITECT cI4100-I1SR"," "};
private static final String[] test = {"Human Chronic Gonadotropin (BhCG) {7K78}(mIU/mL"," "};
private static final String[] method = {"NONE"," "};
private static final String[] reagentArray = {"ABBOTT"," "};
private static final String[] month = {"January, 2015"," "};
private static final String[] shift = {"All"," "};
private static final String[] qcProduct = {"MULTICHEM IA PLUS(05P76-10)"," "};
private static final Double[] chartmean = {3.57,3.88,4.18,4.49,4.79,5.10,5.40,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79,4.79};
private static final Double[] chartsd = {-3.0,-2.0,-1.0,0.0,1.0,2.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0,3.0};
private static final Integer[] daysinmonth = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31};
private static final Double[] controlvalue = {4.49,4.19,5.09,3.89,5.39,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59,3.59};
private static final Double[] cYvalue = {0.00,4.08,4.47,4.18,4.46,4.45,4.52,4.81,4.21,4.52,4.50,4.76,4.48,4.51,4.50,0.00,4.78,4.80,4.79,4.43,4.48,4.51,4.53,4.49,4.90,4.48,4.20,4.49,3.90,4.50,4.48};
private int counter = -1;
/**
* Variables to store the number of fields, and their names, in the report
*/
private HashMap<String, Integer> fieldsNumber = new HashMap<>();
Map<String,List<Integer>> multiMap = new HashMap<>();
/**
* Method used to know if there are records to read.
*/
private int lastFieldsAdded = 0;
public Implementation(List <Records> items) {
// TODO Auto-generated constructor stub
super();
Implementation.items = items;
}
/**
* This method is called for every field defined in the report. So if i have 2 fields it is called 2 times for every record, and
* for each of them it must provide a value.
* The parameter can be used to understand for which field is requested, in fact it contains the name of the requested field. This
* data adapter is done with the goal of return two values, a name and an age. An easy option would be expect a field with the name
* "Name" and one with name "Age". But we can do something more flexible, in this case we will enumerate all the fields requested and
* and the first two will be assumed to be for name and age, for all the others will be returned an empty string. So we can have a report
* with more than two fields, but the name and the age will be returned each time only for the first two.
*
* If this example is too much complex refer to the method getFieldValue2, where is shown the first explained, and simple solution, where we
* expect two fields with a precise name.
*/
@Override
public Object getFieldValue(JRField jrField) throws JRException {
Integer fieldIndex;
//fieldIndex=items.get(counter).getN().length;
Records rec = items.get(counter);
//items
//items.iterator().equals(jrField.getName())
if (fieldsNumber.containsKey(jrField.getName())) {
fieldIndex = fieldsNumber.get(jrField.getName());
}
else {
fieldsNumber.put(jrField.getName(), lastFieldsAdded);
fieldIndex = lastFieldsAdded;
lastFieldsAdded ++;
}
if (fieldIndex == 0) return rec.getLotnum()[counter];//Field_1
else if (fieldIndex == 1) return rec.getLevel()[counter];//Field_2
else if (fieldIndex == 2) return rec.getMean()[counter];//Field_3
else if (fieldIndex == 3) return rec.getSd()[counter];//Field_4
else if (fieldIndex == 4) return rec.getCv()[counter];//Field_5
else if (fieldIndex == 5) return rec.getN()[counter];//Field_6
else if (fieldIndex == 6) return rec.getMean2()[counter];//Field_7
else if (fieldIndex == 7) return rec.getSd2()[counter];//Field_8
else if (fieldIndex == 8) return rec.getCv2()[counter];//Field_9
else if (fieldIndex == 9) return rec.getN2()[counter];//field_10
else if (fieldIndex == 10) return rec.getDepartment()[0];//field_11
else if (fieldIndex == 11) return rec.getInstrument()[0];//field_12
else if (fieldIndex == 12) return rec.getTest()[0];//field_13
else if (fieldIndex == 13) return rec.getMethod()[0];//field_14
else if (fieldIndex == 14) return rec.getReagent()[0];//field_15
else if (fieldIndex == 15) return rec.getMonth()[0];//field_16
else if (fieldIndex == 16) return rec.getShift()[0];//field_17
else if (fieldIndex == 17) return rec.getQcproduct()[0];//field_18
else if (fieldIndex == 18)return rec.getDaysinmonth()[counter];//field_19
else if (fieldIndex == 19)return rec.getChartmean()[counter];//field_20
if (fieldIndex == 20)return rec.getChartmean()[counter];//field_21
if(fieldIndex ==21)return rec.getControlvalue()[counter];//field_22
if(fieldIndex ==22)return rec.getcYvalue()[counter];//field_22
return "";
}
/**
* Method used to know if there are records to read.
*/
@Override
public boolean next() throws JRException {
if (counter< items.toArray().length-1) {
counter++;
return true;
}
return false;
}
/**
* Return an instance of the class that implements the custom data adapter.
*/
public static JRDataSource getDataSource(){
Records rec=new Records();
rec.setLotnum(lotNum);
rec.setLevel(level);
rec.setMean(mean);
rec.setSd(SD);
rec.setCv(CV);
rec.setN(N);
rec.setMean2(mean2);
rec.setSd2(SD2);
rec.setCv2(CV2);
rec.setN2(N2);
rec.setDepartment(department);
rec.setInstrument(instruementArray);
rec.setTest(test);
rec.setMethod(method);
rec.setReagent(reagentArray);
rec.setMonth(month);
rec.setShift(shift);
rec.setQcproduct(qcProduct);
rec.setDaysinmonth(daysinmonth);
rec.setChartsd(chartsd);
rec.setChartmean(chartmean);
rec.setControlvalue(controlvalue);
rec.setcYvalue(cYvalue);
items.add(rec);
return new Implementation(items);
}
, в основном, как я могу получить каждое поле для вызоваболее 2 раз для каждой записи, чтобы сохранить значения в соответствующих полях jr, даже если массив больше или меньше, чем имя и возраст.
Stack Trace:
net.sf.jasperreports.engine.JRException: java.lang.ArrayIndexOutOfBoundsException: 2
at com.jaspersoft.studio.editor.preview.view.control.ReportController.fillReport(ReportController.java:551)
at com.jaspersoft.studio.editor.preview.view.control.ReportController.access$18(ReportController.java:526)
at com.jaspersoft.studio.editor.preview.view.control.ReportController$1.run(ReportController.java:444)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.lang.ArrayIndexOutOfBoundsException: 2
at TheLeveyJen.Implementation.getFieldValue(Implementation.java:94)
at net.sf.jasperreports.engine.fill.JRFillDataset.setOldValues(JRFillDataset.java:1501)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1402)
at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:1378)
at net.sf.jasperreports.engine.fill.JRFillDatasetRun.advanceDataset(JRFillDatasetRun.java:329)
at net.sf.jasperreports.engine.fill.JRFillDatasetRun.iterate(JRFillDatasetRun.java:306)
at net.sf.jasperreports.engine.fill.JRFillDatasetRun.evaluate(JRFillDatasetRun.java:251)
at net.sf.jasperreports.engine.fill.JRFillElementDataset.evaluateDatasetRun(JRFillElementDataset.java:249)
at net.sf.jasperreports.engine.fill.JRFillChart.evaluateDatasetRun(JRFillChart.java:1428)
at net.sf.jasperreports.engine.fill.JRFillChart.evaluateChart(JRFillChart.java:822)
at net.sf.jasperreports.engine.fill.JRFillChart.evaluateRenderer(JRFillChart.java:798)
at net.sf.jasperreports.engine.fill.JRFillChart.resolveElement(JRFillChart.java:1406)
at net.sf.jasperreports.engine.fill.JRFillElement.performDelayedEvaluation(JRFillElement.java:1136)
at net.sf.jasperreports.engine.fill.JRFillElement.resolveElement(JRFillElement.java:1238)
at net.sf.jasperreports.engine.fill.ElementEvaluationAction.execute(ElementEvaluationAction.java:69)
at net.sf.jasperreports.engine.fill.DelayedFillActions.runActions(DelayedFillActions.java:270)
at net.sf.jasperreports.engine.fill.BaseReportFiller.resolveBoundElements(BaseReportFiller.java:802)
at net.sf.jasperreports.engine.fill.JRBaseFiller.resolveReportBoundElements(JRBaseFiller.java:1202)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillSummary(JRVerticalFiller.java:1211)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReportEnd(JRVerticalFiller.java:297)
at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:117)
at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:615)
at net.sf.jasperreports.engine.fill.BaseFillHandle$ReportFill.run(BaseFillHandle.java:135)
at java.lang.Thread.run(Thread.java:748)