• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

getting Null Pointer Exception when adding and element to an attribute ArrayList type in a POJO

 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have this two POJOS


i have this two methods

this method: searchRolesByUser returns a list of roles with a empty permList, i mean the roles dont have perms in this list.

And this method searchPermsByRoleName returns a list of perms

so i want to add to my list roles that have empty perms in their field private ArrayList<Perm> permList those perms that i have in the list that returns the method searchPermsByRoleId

here is the two ways that i have tried to add them but when i get to the part getPermsList().add(perm) i get a null pointer exception.


that method gives me and null pointer exception in this line roleList.get(i).getPermsList().add(permList.get(k));

i dont know why if is the getPermsList() that was the default get that netbeans ide created for me or the deafult add method that have the Arraylist class


and that method gives me a nullpointer exception in this line rol.getPermsList().add(perm);

i dont know why if is the getPermsList() that was the default get that netbeans ide created for me or the deafult add method that have the Arraylist class
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where are you initialising the permList?

That's a guess as to what thing is null.
There could be other things null and you should debug the code to find out (some System.out.println() calls should do it).
 
Jhon Parker
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Where are you initialising the permList?

That's a guess as to what thing is null.
There could be other things null and you should debug the code to find out (some System.out.println() calls should do it).



yes it was that i change my getter method to this

 
reply
    Bookmark Topic Watch Topic
  • New Topic