error: class, interface, or enum expected?

0

So people here were trying to do an exercise of the old game in android studio and I can not find where the error is, I would like some help.

 package com.example.francisco.jogodavelha;

 import android.app.AlertDialog; import
 android.content.DialogInterface; import
 android.support.v7.app.AppCompatActivity; import android.os.Bundle;
 import android.view.Menu; import android.view.MenuItem; import
 android.view.View; import android.widget.Button; import
 android.widget.Toast;

 public class MainActivity extends AppCompatActivity {

     public final int BOLA = 1;
     public final int CRUZ = 2;

     int turno;
     int rodada;

     public void VerificarFim() {
         int vencedor = 0;
         if (bot[0].getValor() == bot[1].getValor() && bot[1].getValor() == bot[2].getValor()) {
             vencedor = bot[0].getValor();
         } else if (bot[3].getValor() == bot[4].getValor() && bot[4].getValor() == bot[5].getValor()) {
             vencedor = bot[3].getValor();
         } else if (bot[6].getValor() == bot[7].getValor() && bot[7].getValor() == bot[8].getValor()) {
             vencedor = bot[6].getValor();
         } else if (bot[0].getValor() == bot[3].getValor() && bot[3].getValor() == bot[6].getValor()) {
             vencedor = bot[0].getValor();
         } else if (bot[1].getValor() == bot[4].getValor() && bot[4].getValor() == bot[7].getValor()) {
             vencedor = bot[1].getValor();
         } else if (bot[2].getValor() == bot[4].getValor() && bot[4].getValor() == bot[8].getValor()) {
             vencedor = bot[2].getValor();
         } else if (bot[0].getValor() == bot[4].getValor() && bot[1].getValor() == bot[2].getValor()) {
             vencedor = bot[0].getValor();
         } else if (bot[2].getValor() == bot[4].getValor() && bot[4].getValor() == bot[6].getValor()) {
             vencedor = bot[2].getValor();
         }
         if (rodada > 9 && vencedor == 0) {
             vencedor = -1;
         }
         if (vencedor != 0) {
             String textovit = "";
             if (vencedor == BOLA) {
                 textovit = "Bola Venceu, ";
             } else if (vencedor == CRUZ) {
                 textovit = "Cruz Venceu, ";
             } else {
                 textovit = "Houve um empate";
             }
             textovit += "Deseja jogar novamente?";
         }

         AlertDialog.Buider buider = new AlertDialog.Builder(MainActivity.this);

         builder.setTitle("Fim de jogo");
         buider.setMessage(textovit);
         builder.setCancelable(false);

         buider.setPositiveButton("Jogar", new DialogInterface.OnClickListener() {
             public void onClick(DialogInterface dialog, int which) {
                 for (int i = 0; i<9; i++){
                     bot[i].getBot().setEnabled(true);
                     bot[i].getBot().setText("");
                     bot[i].setValor(0);
                 }
             }
         });
         builder.setNegativeButton("sair", new DialogInterface.OnClickListener(){
             public void onClick (DialogInterface dialog,int which){
                 finish();
             }
         });

         AlertDialog alert = builder.create();
         alert.show();
     } 
}

 class Botao {
     private Button bot;
     private int valor;

     public void setValor(int valor) {
         this.valor = valor;
     }

     public Button getBot() {
         return this.bot;
     }

     public int getValor() {
         return this.valor;
     }

     public Botao(Button bot) {
         this.bot = bot;
         this.valor = 0;
         this.bot.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 getBot().setEnabled(false);
                 setValor(turno);
                 if (turno == BOLA) {
                     getBot().setText("0");
                     turno = CRUZ;
                 } else {
                     getBot().setText("X");
                     turno = BOLA;
                 }
                 rodada++;
                 VerificarFim();
             }

         });
     }
 }
     Botao[] bot;

     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         turno = BOLA;
         rodada = 1;
         bot = new Botao[9];
         bot[0] = new Botao ( (Button) findViewById(R.id.bot1));
         bot[1] = new Botao ( (Button) findViewById(R.id.bot2));
         bot[2] = new Botao ( (Button) findViewById(R.id.bot3));
         bot[3] = new Botao ( (Button) findViewById(R.id.bot4));
         bot[4] = new Botao ( (Button) findViewById(R.id.bot5));
         bot[5] = new Botao ( (Button) findViewById(R.id.bot6));
         bot[6] = new Botao ( (Button) findViewById(R.id.bot7));
         bot[7] = new Botao ( (Button) findViewById(R.id.bot8));
         bot[8] = new Botao ( (Button) findViewById(R.id.bot9));

     }
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
         // Inflate the menu; this adds items to the action bar if it is present.
         getMenuInflater().inflate(R.menu.menu_main, menu);
         return true;
     }
 }
    
asked by anonymous 03.12.2015 / 00:09

1 answer

0

If your MainActivity is exactly the way you posted in your question, your problem is at the end of your class.

This part of the code (below) probably belongs to your MainActivity and is currently nowhere, because you have a wrong key lock ( } ) wrong somewhere.

 Botao[] bot;

 @Override
 public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
     setContentView(R.layout.activity_main);
     turno = BOLA;
     rodada = 1;
     bot = new Botao[9];
     bot[0] = new Botao ( (Button) findViewById(R.id.bot1));
     bot[1] = new Botao ( (Button) findViewById(R.id.bot2));
     bot[2] = new Botao ( (Button) findViewById(R.id.bot3));
     bot[3] = new Botao ( (Button) findViewById(R.id.bot4));
     bot[4] = new Botao ( (Button) findViewById(R.id.bot5));
     bot[5] = new Botao ( (Button) findViewById(R.id.bot6));
     bot[6] = new Botao ( (Button) findViewById(R.id.bot7));
     bot[7] = new Botao ( (Button) findViewById(R.id.bot8));
     bot[8] = new Botao ( (Button) findViewById(R.id.bot9));

 }
 @Override
 public boolean onCreateOptionsMenu(Menu menu) {
     // Inflate the menu; this adds items to the action bar if it is present.
     getMenuInflater().inflate(R.menu.menu_main, menu);
     return true;
 }
}

If your Botao class is a innerClass , you should remove the% keys from } just before the class Botao { line if it is an external class your MainActivity you should get the code above and put before of keys close before class Botao

    
03.12.2015 / 00:38