Hi guys,
I'm new here, as well, very tired from coding (alot of trial and error) for the past few hours.
I have an intro to java class under my belt and I'm having alot of trouble with Exceptions in my application. The issue is that I have multiple EditTexts for numerical entry and the data is then used in a formula. The formula is then supposed to output to another EditText. I'm just having a lot of difficulty with the formula part and outputting.
Here's the code, any help would be much appreciated, thanks.
If you need the rest, I don't have a problem posting it but I am quite certain the problem is here, my variables are declared private at the beginning.
I'm new here, as well, very tired from coding (alot of trial and error) for the past few hours.
I have an intro to java class under my belt and I'm having alot of trouble with Exceptions in my application. The issue is that I have multiple EditTexts for numerical entry and the data is then used in a formula. The formula is then supposed to output to another EditText. I'm just having a lot of difficulty with the formula part and outputting.
Here's the code, any help would be much appreciated, thanks.
Code:
private void Home(){
avg = (EditText) findViewById(R.id.avg);
avg.setFilters(new InputFilter[] {new DecimalDigitsInputFilter(3,2)});
cavg = (EditText) findViewById(R.id.cavg);
cavg.setFilters(new InputFilter[] {new DecimalDigitsInputFilter(3,2)});
std = (EditText) findViewById(R.id.stddev);
std.setFilters(new InputFilter[] {new DecimalDigitsInputFilter(3,2)});
isg = (EditText) findViewById(R.id.isg);
isg.setFilters(new InputFilter[] {new DecimalDigitsInputFilter(3,2)});
calculate = (Button)findViewById(R.id.calculate);
reset = (Button)findViewById(R.id.reset);
calculate.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){
try {
calculate();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}});
reset.setOnClickListener(new Button.OnClickListener() { public void onClick (View v){ try {
reset();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
} }});
}
private void calculate() throws Exception{
double CRC = 0;
Log.d("calculate", "Before the variables");
a=Double.parseDouble(avg.getText().toString());
c=Double.parseDouble(cavg.getText().toString());
s=Double.parseDouble(std.getText().toString());
i=Double.parseDouble(isg.getText().toString());
Log.d("calculate", "After the variables");
CRC = 5 * (((a - c) / s) + 5 + ((i - 75) / 14));
Log.d("calculate", "After calculation");
RC.setText(Double.toString(CRC));
Log.d("calculate", "displaying");
}