FATAL EXCEPTION:
Main Process: com.example.joquempo, PID: 4111 java.lang.IllegalStateException:
Could not execute method for android:onClick
I don't know what is the problem here, images are well-linked. I am basically trying to create a jokempo game, supposed to be quite easy but now I am receiving the error above which stuck me on this.
package com.example.joquempo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.Random;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void selecionadoPedra(View view) {
this.opcaoSelecionada("pedra");
}
public void selecionadoPapel(View view) {
this.opcaoSelecionada("papel");
}
public void selecionadoTesoura(View view) {
this.opcaoSelecionada("tesoura");
}
public void opcaoSelecionada(String opcaoSelecionada) {
ImageView imageResultado = findViewById(R.id.imageResultado);
TextView textResultado = findViewById(R.id.textResultado);
int numero = new Random().nextInt(3);
String[] opcoes = {"pedra", "papel", "tesoura"};
String opcaoApp = opcoes[numero];
switch (opcaoApp) {
case "pedra":
imageResultado.setImageResource(R.drawable.pedra);
break;
case "papel":
imageResultado.setImageResource(R.drawable.papel);
break;
case "tesoura":
imageResultado.setImageResource(R.drawable.tesoura);
break;
}
if ((opcaoApp.equals("tesoura") && opcaoSelecionada.equals("papel")) ||
(opcaoApp.equals("papel") && opcaoSelecionada.equals("pedra")) ||
(opcaoApp.equals("pedra") && opcaoSelecionada.equals("tesoura"))) {
textResultado.setText("Você Perdeu :( ");
} else if ((opcaoSelecionada.equals("tesoura") && opcaoApp.equals("papel")) ||
(opcaoSelecionada.equals("papel") && opcaoApp.equals("pedra")) ||
(opcaoSelecionada.equals("pedra") && opcaoApp.equals("tesoura"))) {
textResultado.setText("Você ganhou! :D ");
} else {
textResultado.setText("Empatamos ;) ");
}
}