I have a csv file that my class with the code below is trying to read that data to use in my project, but when i run the project, I have a NullPointerException like the csv file is null, but he isn't. The path of the csv file is right and apparently I don't have any error in my class too, what I am missing?
package main.java.br.com.quantumfinance.selecaoEstagio.leitor;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
public class LeitorDeArquivo {
public List<String> lerArquivo() {
try (InputStream resourceAsStream = LeitorDeArquivo.class.getResourceAsStream("/acoes.csv")) {
// Leitura do arquivo.
BufferedReader br = new BufferedReader(new InputStreamReader(resourceAsStream));
// ignora a primeira linha
br.readLine();
List<String> cotacoes = new ArrayList<>();
String linha;
while ((linha = br.readLine()) != null) {
cotacoes.add(linha);
}
return cotacoes;
} catch (FileNotFoundException e) {
System.out.println("Arquivo n�o encontrado.");
e.printStackTrace();
} catch (IOException e) {
System.out.println("Erro de IO.");
e.printStackTrace();
}
throw new RuntimeException("Erro na leitura do arquivo, consulte o console para maiores detalhes.");
}
}
This is the error that I receive when trying to run the project
Exception in thread "main" java.lang.NullPointerException
at java.base/java.io.Reader.<init>(Reader.java:168)
at java.base/java.io.InputStreamReader.<init>(InputStreamReader.java:76)
at main.java.br.com.quantumfinance.selecaoEstagio.leitor.LeitorDeArquivo.lerArquivo(LeitorDeArquivo.java:17)
at main.java.Questoes.main(Questoes.java:26)
This is the project structure