5
I created this Arraylist and at the moment of execution the following message appears:
Error: Main method not found in class Declaracaoarray.Declaracao_array; set the main method to:
public Static void main(String[] args)
Reading the message, and with the help of colleagues here at SOPT, it is noticed that in my code the main method is missing, my doubt is Where do I put this method? I have tried in many ways, but without success.
What would my code look like with this new method?
package DeclaracaoArray;
import java.util.List;
import java.util.ArrayList;
import java.util.Collections;
public class Declaracao_Array {
public String sorteia (){
List<String> lista = new ArrayList<String>();
lista.add ( "Alice" );
lista.add ( "Bruno" );
lista.add ( "Carlos");
lista.add ( "Daniel");
Collections.shuffle ( lista );
return lista.get(0);
}
}
Is this your main class? If so, as the error message already says, the
void main
in it,– emanuelsn
Are you trying to run this class only? Without the main method it won’t run at all. Add the <code>'public Static void main(String args[]){}'</code> method and run again.
– user28595