0
I’m trying to call a method in main
, but the class won’t allow me to do it.
Error appears:
"Cannot Make aStiatic References to the non-static method"
I own the class Gerenciamento
, where the method is contained:
public class Gerenciamento {
public double totalCaixa;
private ArrayList<Bicicleta> bicicletas = new ArrayList<Bicicleta>();
Scanner leitor = new Scanner(System.in);
public void cadastrarBicicleta()
{
String cor = null, marca = null, modelo = null, acessorio = null;
int numIdBici = (bicicletas.size());
boolean ok = false;
System.out.print("\n----- Cadastro de Bicicleta -----\n\nInsira cor: ");
do {
try {
cor = leitor.nextLine();
} catch (Exception x) {
ok = true;
}
} while (ok == true);
System.out.print("\nInsira marca: ");
do {
try {
marca = leitor.nextLine();
} catch (Exception x) {
ok = true;
}
} while (ok == true);
System.out.print("\nInsira modelo: ");
do {
try {
modelo = leitor.nextLine();
} catch (Exception x) {
ok = true;
}
} while (ok == true);
System.out.print("\nInsira acessorios: ");
do {
try {
acessorio = leitor.nextLine();
} catch (Exception x) {
ok = true;
}
} while (ok == true);
boolean disponivel = true;
bicicletas.add(new Bicicleta (numIdBici,cor, marca, modelo, acessorio, disponivel));
numIdBici = (bicicletas.size());
System.out.println("\n##### Bicicleta criada com sucesso! #####");
}
And I own the main, where I can’t call the method
public class TesteCicloTurismo extends Gerenciamento
{
public static void main(String[] args)
{
Scanner leitor = new Scanner(System.in);
int opcao;
do
{
switch(opcao)
{
case 1:
cadastrarBicicleta();//metodo nao pode ser chamado aqui
break;
}
}
Thank you so much! I was even ashamed now, to ask something so easy hah
– DacK R.
@Dackr. Hey, don’t be embarrassed. We all go through this phase of learning :)
– gabrielfalieri
@gabrielfalieri ?? If it was pro OP, you can quote it so that the message is directed to it by putting "@"+the name used by it :)
– user28595