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
  • 13,793
  • 6
  • 30
  • 42
Michał Styś
  • 1,433
  • 3
  • 10
  • 15

2 Answers2

1

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

List<ManagedFilesAuthorityDTO> outputFileList = new ArrayList<>();
Gherbi Hicham
  • 2,207
  • 4
  • 23
  • 40
0

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

List<ManagedFilesAuthorityDTO> outputFileList = new ArrayList<>();
Shiro
  • 2,570
  • 2
  • 16
  • 34