0

I have short question because I can't understand my mistake.

I have a collections:

      List<ManagedFilesAuthorityDTO> managedFilesAuthorityDTOs = filesAuthorityRepository.findAll().stream()
        .map(ManagedFilesAuthorityDTO::new)
        .collect(Collectors.toList());

then I'm creating new list

List<ManagedFilesAuthorityDTO> outputFileList = null;

and I would like to iterate for managedFilesAuthorityDTOs and assign some object to outputFileList.

Here's my loop:

 for (ManagedFilesAuthorityDTO dto : managedFilesAuthorityDTOs) {
        outputFileList.add(dto);
    }

And I still getting NullPointerException because my outputFileList is equals null. What I am doing wrong that I can't create new List?

Theodore Norvell
  • 15,366
  • 6
  • 31
  • 45
Michał Styś
  • 1,743
  • 3
  • 12
  • 16

2 Answers2

1

you're not creating a new list, this is how you do it:

List<ManagedFilesAuthorityDTO> outputFileList = new ArrayList<>();
Gherbi Hicham
  • 2,416
  • 4
  • 26
  • 41
0

You are not creating a list, you are setting it to null. Should be:

List<ManagedFilesAuthorityDTO> outputFileList = new ArrayList<>();
Shiro
  • 2,610
  • 2
  • 20
  • 36