0
I cannot pass a method to get the name of the files in a folder.
I have the code below:
inicializar.addWindowListener(new WindowListener(){
@Override
public void windowOpened(WindowEvent arg0){
DefaultListModel dlm = new DefaultListModel();
JList lstvRel = new JList();
lstvRel.setModel(dlm);
ListarArquivos l = new ListarArquivos();
dlm = l.listar(); //Erro nesta linha!!
for(int i = 0; i < l.listar().size(); i++){
lstvRel.getModel().getElementAt(i).toString();
}
}
And the class:
public class ListarArquivos {
public void listar() {
File dirArquivos = new File("C:\\Users\\lbell\\Desktop\\Turbo - teste");
File[] Arquivos = dirArquivos.listFiles((File b) -> b.getName().endsWith(".xls") ||
b.getName().endsWith(".xlsx") ||
b.getName().endsWith(".xlsm") ||
b.getName().endsWith(".xlsb") ||
b.getName().endsWith(".ppt"));
}
}
The method returns
void
, what’s waiting for him to return?– Renan Gomes
As Renan said, the list method is
void
, there is no return, and you are trying to assign a return that does not exist to a variable.– user28595
Sorry to be unaware, I’m new to java and I’m creating a report generator program. In the case then how could I create a return to my void generate an array. The intention is to popular a Jlist when initializing the program.
– Leandro Bellizzi