I want to call a public List<String> method in main

Asked

Viewed 67 times

0

public class Conteudo {   
    public List<String> Matriz(String[] array){

        String CaminhoArquivo=("C:\\Users\\jessica borges"
                + "\\Downloads\\CalculadoraMatrizes-20190315T112959Z-001"
                + "\\CalculadoraMatrizes-20190315T112959Z-001"
                + "\\CalculadoraMatrizes\\src\\ArquivosMatriz\\matrix.txt");

        List<String> conteudo = new ArrayList<>(); 
            try {
                BufferedReader in = new BufferedReader(new FileReader(CaminhoArquivo));

     String linha;
                while ((linha = in.readLine()) != null) { 
                   int var[] = new int[conteudo.size()];
                    conteudo.addAll(Arrays.asList(linha.split(" ")));
                return conteudo;    
            }   
             in.close();
        } catch (IOException ioe) {
            System.out.println(ioe);
        } return conteudo;
    }
}

I need to call this method in the main method, I’m doing so (but gives error):

public static void main(String[] args){
   chamarMatriz();
}
public void chamarMatriz(){
   Conteudo ct = new Conteudo();
   List<conteudo> oct  = new List<conteudo>();
    ct.Matriz(conteudo);
}

1 answer

0


The main method is static it has no access to the non-static methods within the class, for this you need to instantiate first the class that contains the call method:

public static void main(String[] args){
   ClasseQueTemOMetodoChamarMatriz classe = new ClasseQueTemOMetodoChamarMatriz();
   classe.chamarMatriz();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.