I am creating an application but in case it is giving a problem when running up to a certain point, I want to transform geoi = 0; and mati = 0; , and when I add any number in edittext it will put that number inside the int geoi and mati that in the case equals 0. What is the error in my code? Why are you giving Unfortunately?
package com.gustavo.sample;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends ActionBarActivity {
CheckBox g;
CheckBox m;
Button send;
TextView say;
EditText num;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
bacon();
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String counter = num.getText().toString();
int counterAsInt = Integer.parseInt(counter);
int geoi = 0;
int mati = 0;
if(g.isChecked()){
geoi += counterAsInt;
say.setText("Geo" + geoi);
}
else if(m.isChecked()){
mati += counterAsInt;
say.setText("Math" + mati);
}
}
});
}
public void bacon() {
g = (CheckBox)findViewById(R.id.checkBox1);
m = (CheckBox)findViewById(R.id.checkBox2);
send = (Button)findViewById(R.id.button1);
say = (TextView)findViewById(R.id.textView1);
num = (EditText)findViewById(R.id.editText1);
}
}