Tuesday, 3 September 2013

null pointer exception - jxls, markAsFixedSizeCollection

null pointer exception - jxls, markAsFixedSizeCollection

I'm getting a null pointer exception when using the XLSTransformer's
markAsFixedSizeCollection method. Actually, the exception itself occurs at
net.sf.jxls.util.Util.duplicateRowCollectionProperty(Util.java:238).
Here's the code:
package com.mycomp;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import com.sun.media.sound.InvalidFormatException;
import net.sf.jxls.exception.ParsePropertyException;
import net.sf.jxls.transformer.XLSTransformer;
public class TestJXL {
public TestJXL() throws ParsePropertyException,
InvalidFormatException, IOException{
ArrayList<Employee> staff = new ArrayList<Employee>();
staff.add(new Employee("Derek", 35, 3000, 0.30));
staff.add(new Employee("Elsa", 28, 1500, 0.15));
staff.add(new Employee("Oleg", 32, 2300, 0.25));
staff.add(new Employee("Neil", 34, 2500, 0.00));
staff.add(new Employee("Maria", 34, 1700, 0.15));
staff.add(new Employee("John", 35, 2800, 0.20));
staff.add(new Employee("Leonid", 29, 1700, 0.20));
HashMap<String, ArrayList<Employee>> beans = new
HashMap<String, ArrayList<Employee>>();
beans.put("employee", staff);
XLSTransformer transformer = new XLSTransformer();
transformer.markAsFixedSizeCollection("employee");
String templateFileName = "C:\\0temp2\\test.xls";
String destFileName = "C:\\0temp2\\dest.xls";
try {
transformer.transformXLS(templateFileName, beans,
destFileName);
} catch
(org.apache.poi.openxml4j.exceptions.InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String [] args) throws
ParsePropertyException, InvalidFormatException, IOException{
new TestJXL();
}
}
package com.mycomp;
import java.util.Date;
public class Employee {
private String name;
private int age;
private Double payment;
private Double bonus;
private Date birthDate;
private Employee superior;
public Employee(String name, int age, Double payment, Double bonus) {
this.name = name;
this.age = age;
this.payment = payment;
this.bonus = bonus;
}
public Employee(String name, int age, double payment, double bonus, Date
birthDate) {
this.name = name;
this.age = age;
this.payment = new Double(payment);
this.bonus = new Double(bonus);
this.birthDate = birthDate;
}
public Employee(String name, int age, double payment, double bonus) {
this.name = name;
this.age = age;
this.payment = new Double(payment);
this.bonus = new Double(bonus);
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public Double getPayment() {
return payment;
}
public void setPayment(Double payment) {
this.payment = payment;
}
public Double getBonus() {
return bonus;
}
public void setBonus(Double bonus) {
this.bonus = bonus;
}
public Date getBirthDate() {
return birthDate;
}
public void setBirthDate(Date birthDate) {
this.birthDate = birthDate;
}
public Employee getSuperior() {
return superior;
}
public void setSuperior(Employee superior) {
this.superior = superior;
}
}
Here's the stack trace:
Exception in thread "main" java.lang.NullPointerException
at net.sf.jxls.util.Util.duplicateRowCollectionProperty(Util.java:238)
at
net.sf.jxls.transformer.CollectionRowTransformer.processRowCollections(CollectionRowTransformer.java:116)
at
net.sf.jxls.transformer.CollectionRowTransformer.transform(CollectionRowTransformer.java:66)
at
net.sf.jxls.transformer.SheetTransformer.transformSheet(SheetTransformer.java:88)
at
net.sf.jxls.transformer.XLSTransformer.transformWorkbook(XLSTransformer.java:248)
at
net.sf.jxls.transformer.XLSTransformer.transformXLS(XLSTransformer.java:221)
at
net.sf.jxls.transformer.XLSTransformer.transformXLS(XLSTransformer.java:201)
at com.mycomp.TestJXL.<init>(TestJXL.java:32)
at com.mycompl.TestJXL.main(TestJXL.java:40)
The template and code is as suggested in:
http://jxls.sourceforge.net/reference/collections.html
Any suggestions appreciated.

No comments:

Post a Comment