Announcement Announcement Module
Collapse
No announcement yet.
NullPointerException in BeanWrapperFieldSetMapper Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • NullPointerException in BeanWrapperFieldSetMapper

    I am getting NullPointerException in BeanWrapperFieldSetMapper class while reading the flat file using Spring Batch. I here with given the details below. Please help me out of the Problem.

    Code:
    Caused by: java.lang.NullPointerException
    	at org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper.findPropertyName(BeanWrapperFieldSetMapper.java:273)
    	at org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper.findPropertyName(BeanWrapperFieldSetMapper.java:290)
    	at org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper.getBeanProperties(BeanWrapperFieldSetMapper.java:260)
    	at org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper.mapFieldSet(BeanWrapperFieldSetMapper.java:172)
    	at org.springframework.batch.item.file.mapping.DefaultLineMapper.mapLine(DefaultLineMapper.java:46)
    	... 31 more
    Spring Batch Configuration for Reader

    Code:
    <beans:bean id="playerFileItemReader" 
    class="org.springframework.batch.item.file.FlatFileItemReader">
    <!--  <beans:property name="resource" 
    value="classpath:input/player.csv" /> -->
    <beans:property name="resource" value="file:c:\data\input\player.csv" />		
    <beans:property name="lineMapper">
    <beans:bean 
    class="org.springframework.batch.item.file.mapping.DefaultLineMapper">	
    <beans:property name="lineTokenizer">				
    <beans:bean 
    class="org.springframework.batch.item.file.transform.DelimitedLineTokenizer">
    <beans:property name="delimiter" value=","/>
    <beans:property name="names" 
    value="ID,lastName,firstName,position,CareerPeriod.debutYear,CareerPeriod.finalYear" />
    </beans:bean>
    </beans:property>
    <beans:property name="fieldSetMapper">
    <beans:bean class="org.springframework.batch.item.file.mapping.BeanWrapperFieldSetMapper">
    <beans:property name="targetType" value="com.ecomputercoach.file.Player"/>
    </beans:bean>
    </beans:property>
    </beans:bean>
    </beans:property>
    </beans:bean>
    Player.java
    Code:
    public class Player implements Serializable 
    {
    
    	private String id; 
    	private String lastName; 
    	private String firstName; 
    	private String position;
    	private CareerPeriod careerPeriod;
    	
    	@SuppressWarnings("unused")
    	private String fullName;
    	private double careerLength;	
     
    	public String getId() {
    		return id;
    	}
    	public String getLastName() {
    		return lastName;
    	}
    	public String getFirstName() {
    		return firstName;
    	}
    	public String getPosition() {
    		return position;
    	}
     
    	public void setId(String id) {
    		this.id = id;
    	}
    	public void setLastName(String lastName) {
    		this.lastName = lastName;
    	}
    	public void setFirstName(String firstName) {
    		this.firstName = firstName;
    	}
    	public void setPosition(String position) {
    		this.position = position;
    	}
     
    	public String getFullName() {
    		return this.firstName+" "+this.lastName;
    	}	
     
    	public void setFullName(String fullName) {
    		this.fullName = fullName;
    	}
    	public double getCareerLength() {
    		return careerLength;
    	}
    	
    	public void setCareerLength(double careerLength) {
    		this.careerLength = careerPeriod.getFinalYear() - careerPeriod.getDebutYear();
    	}
    	
    	public CareerPeriod getCareerPeriod() {
    		return careerPeriod;
    	}
    	public void setCareerPeriod(CareerPeriod careerPeriod) {
    		this.careerPeriod = careerPeriod;
    	}		
    }
    CareerPeriod.java
    Code:
    public class CareerPeriod implements Serializable {
    	private int debutYear; 
    	private int finalYear;
    	
    	public int getDebutYear() {
    		return debutYear;
    	}
    	public void setDebutYear(int debutYear) {
    		this.debutYear = debutYear;
    	}
    	public int getFinalYear() {
    		return finalYear;
    	}
    	public void setFinalYear(int finalYear) {
    		this.finalYear = finalYear;
    	}
    }

  • #2
    The line numbers in the stack trace don't match the most recent version. I suggest you upgrade and try again?

    Comment


    • #3
      Thanks Dave. previously i used Spring Batch 2.0.4 version. It is working fine with the latest version.

      Comment

      Working...
      X