Non-static variable

3 respostas
errosjava
Igor_Sabarense

boa noite, estou tentando referenciar um objeto da seguinte maneira:

Partida part = new Partida();
porém o compilador está apontando o erro de method non-static

Não consigo entender o por que não consigo abrir a conexão. Segue o código.

public class TP01P2Q01{

public static void main(String[]args){

MyIO.setCharset(UTF-8);

String sites [] = new String[1000];

boolean flag = false;

int i=0;
do{
 sites[i] = MyIO.readLine();
 flag=FlagF(sites[i]);
 i++;
}while(flag==false);

i;

int aux=i;

Partida part = new Partida();

for(i=0;i<aux;i++){

<a href="//part.Ler">//part.Ler</a>(sites[i]);

part.Imprimir();

}

}
public static boolean FlagF(String palavra){

String fim=FIM;

boolean vf = false;

for(int i=0;i<fim.length();i++){

if(palavra.charAt(i)!=fim.charAt(i))

return false;

else

vf=true;
}

return vf;

}

class Partida{

private int copa, placar1, placar2, dia, mes;
private String etapa, time1, time2, local;

/**
*@param copa
*@param placar1
*@param placar2
*@param dia
*@param mes
*@param etapa
*@param time1
*@param time2
*@param local
**/

void Partida(){
  this.copa=0;
  this.placar1=0;
  this.placar2=0;
  this.dia=0;
  this.mes=0;
  this.etapa="";
  this.time1="";
  this.time2="";
  this.local="";
}

void Partida(int copa, int placar1, int placar2, int dia, int mes, String etapa, String time1, String time2, String local){
  this.setCopa(copa);
  this.setPlacar1(placar1);
  this.setPlacar2(placar2);
  this.setDia(dia);
  this.setMes(mes);
  this.setEtapa(etapa);
  this.setTime1(time1);
  this.setTime2(time2);
  this.setLocal(local);
}


/*** GETTERS & SETTERS ***/

void setCopa(int copa){
  this.copa=copa;
}

void setPlacar1(int placar1){
  this.placar1=placar1;
}

void setPlacar2(int placar2){
  this.placar2=placar2;
}

void setDia(int dia){
  if(dia>=1 && dia<=31){
    this.dia=dia;
  }
}

void setMes(int mes){
  if(mes>=1 && mes<=12){
    this.mes=mes;
  }
}

void setEtapa(String etapa){
  this.etapa=etapa;
}

void setTime1(String time1){
  this.time1=time1;
}

void setTime2(String time2){
  this.time2=time2;
}

void setLocal(String local){
  this.local=local;
}

int getCopa(){
  return copa;
}

int getPlacar1(){
  return placar1;
}

int getPlacar2(){
  return placar2;
}

int getDia(){
  return dia;
}

int getMes(){
  return mes;
}

String getEtapa(){
  return etapa;
}

String getTime1(){
  return time1;
}

String getTime2(){
  return time2;
}

String getLocal(){
  return local;
}

/*** GETTERS & SETTERS ***/

void Imprimir(){
  System.out.println("[COPA "+getCopa()+"]"+" - "+ getEtapa() + " - " + getDia()+"/"+getMes()+ " - "+ getTime1()+" ("+getPlacar1()+") x ("+getPlacar2()+") "+getTime2()+ " - "+getLocal());
}

String limpaTag(String s){
  for ( int i = s.indexOf("<"); s.contains("<") && s.contains(">"); i = s.indexOf("<") )
  {
    int j = s.indexOf(">");

    s = s.replace(s.substring(i, (j+1)), "" );
  }
  return s;
}

}
}

3 Respostas

SergioLucas

A Class Partida não está dentro de um método Static? por isso está acontecendo o erro?

Igor_Sabarense

de fato , percebi que havia uma chave que não foi fechada no metodo de Flag. Obrigado!

SergioLucas

Por nada @Igor_Sabarense, Só Edita o título do post e coloca [RESOLVIDO]

Criado 9 de março de 2018
Ultima resposta 9 de mar. de 2018
Respostas 3
Participantes 2