0

I have a list which i have initialised. i get a null pointer exception when i try to add to it. does anyone know why. here is a snippet of the problem-causing code.

Employee e=employeeskills.get(0).getEmployee(); 
    List<EmployeeSkills> es;
    es=e.getEmployeeskills();
    for(int i=0; i<employeeskills.size();i++)
    {   
        es.add(employeeskills.get(i));
    }
    session.getCurrentSession().saveOrUpdate(e);

employeeskills is an list of objects(EmployeeSkills). EmployeeSkills is the a type of Object.

  • 2
    try to use your debugger. – nano_nano Sep 11 '15 at 11:02
  • How does the implementation of ``getEmployeeskills()`` look like? Does it really return a valid List instance? – user1438038 Sep 11 '15 at 11:04
  • thanks for the quick reply :) yes it does return a valid list of EmployeeSkills. If it hadnt eclipse would have thrown an error. – hello.world.lav Sep 11 '15 at 11:05
  • @user1438038 List is a interface, it can not be instantiated, i bet it returns an List implementation class. However OP does not create an instance of List implementations but just refer to the reference which method getEmployeesSkills() return, i think here is the problem. – drgPP Sep 11 '15 at 11:05
  • getEmployeeSkills is a getter method of a class which returns a list of EmployeeSkills. Can you give me a hint on how to fix this? – hello.world.lav Sep 11 '15 at 11:14

0 Answers0