0

I have two EditTexts that have two different values and a button, on click of that button, result of the multiplication should be displayed in the third Edit Text.

Code Written for the function on the button click:

public void Multiply (View view)
{
String str1 = ed1.getText().toString();
        String str2 = ed2.getText().toString();

        int num1 = Integer.parseInt(str1);
        int num2 = Integer.parseInt(str2);

        int prod = num1*num2;

        //Toast.makeText(getBaseContext(), "Product is"+(num1*num2),Toast.LENGTH_LONG ).show();

        ed3.setText(prod);

}
1
  • 1
    You set int value, but Android expext integer == Resource id. So you need to convert prod to String. ed3.setText(String.valueOf(prod)); Commented Jun 12, 2013 at 8:42

4 Answers 4

2

Mistake:

 ed3.setText(prod);

Try:

ed3.setText(String.valueOf(prod));
Sign up to request clarification or add additional context in comments.

Comments

1

Use

ed3.setText(String.valueOf(prod));

or

ed3.setText(""+prod);

Comments

0

EditText won't allow integer to go directly in setText. So convert it into string before setting it

Try this

ed3.setText(String.valueOf(prod));

6 Comments

It is displaying some syntax error, asking to insert ')' after the expression.
Hmm.. Wired have you tried this one ed3.setText(String.valueOf(prod));
I have used exactly the same expression, but it is displaying this error.
I'm sharing the whole code with you. Kindly cross-check, I didnt find any braces left unopened. public void Multiply(View view) { String str1 = ed1.getText().toString(); String str2 = ed2.getText().toString(); int num1 = Integer.parseInt(str1); int num2 = Integer.parseInt(str2); int product = num1*num2; ed3.setText(String.valueOf(product)); }
Vino : I'm waiting for your reply, as I'm new here, so don't know much about it, respond ASAP.
|
0

you can simple add ed3.setText(""+prod); as edittext directly not accept the integer value.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.