0
I’m new in android/java programming and then I came up with this error.
public class Activity_2 extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_activity2);
getSupportActionBar().hide();
Spinner alvos = (Spinner) findViewById(R.id.alvos);
Spinner posicoes = (Spinner) findViewById(R.id.posicoes);
ImageButton hit = (ImageButton) findViewById(R.id.hit);
ImageButton miss = (ImageButton) findViewById(R.id.miss);
int contador = getIntent().getIntExtra("cont", 0);
int sum = getIntent().getIntExtra("targ", 0);
Integer [] arrayAlvos = new Integer[sum];
for(int i=1; i<=sum; i++){
arrayAlvos[i-1]=i;
}
ArrayAdapter<Integer> adapter = new ArrayAdapter<Integer>(this,android.R.layout.simple_dropdown_item_1line, arrayAlvos);
alvos.setAdapter(adapter);
ArrayAdapter pos = ArrayAdapter.createFromResource(this, R.array.posicao, android.R.layout.simple_dropdown_item_1line);
posicoes.setAdapter(pos);
hit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(tiro.this);
alert.setMessage("Certo");
alert.show();
contador++;
}
});
miss.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder alert = new AlertDialog.Builder(tiro.this);
alert.setMessage("Errado");
alert.show();
contador++;
}
});
}
}
I created the variable int contador = getIntent().getIntExtra("cont", 0);
to know the limit.
Then in the buttons part whenever I clicked a button it incremented +1 to the counter variable. Only in the part where I have contador++
he gives me this mistake:
variable contador is accessed from Within Inner class needs to be declared final android
only that I can’t change to the end because my goal is to always change the value. Some solution?!