Reputation: 7003
I'm trying to make an app that would calculate the income tax of a given person. There is an EditText field where the user must point out his monthly wage and then it's being calculated in the MainActivity.java. The problem is - when I try to do some maths using the given input field, an error The operator * is undefined for the argument type(s) EditText, double
shows up.
wage = (EditText) findViewById(R.id.wage);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
wageAfterTax = wage * 0.25;
result.setText("Your wage after tax deductions is " + wageAfterTax);
}
});
Can you please suggest what to do?
Upvotes: 0
Views: 704
Reputation: 38595
wage
is a reference to an EditText object. You need to get the text from it and convert that to a number first.
wage = (EditText) findViewById(R.id.wage);
submit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String wageText = wage.getText().toString();
double wageAmount = Double.valueOf(wageText);
wageAfterTax = wageAmount * 0.25;
result.setText("Your wage after tax deductions is " + wageAfterTax);
}
});
Upvotes: 4