1

I'm trying to get the text of an edittext and convert it to int but I'm facing this error:

android.content.res.Resources$NotFoundException: String resource ID #0x5

the code is very simple:

  temp=String.valueOf(editm.getText());

                minput = Integer.parseInt(temp);
                Toast.makeText(this, minput, Toast.LENGTH_SHORT).show();

temp is a string variable and minput is int type. also I've tried .tostring() & Integer.valueof()

7
  • is your text in input is a number value ? Commented Feb 9, 2019 at 8:58
  • What is the type of temp? Commented Feb 9, 2019 at 8:58
  • Include the code that you are using to initialize editm (the EditText reference) Commented Feb 9, 2019 at 9:00
  • @MoHammaDReZaDehGhani u mean the input type of edittext? Commented Feb 9, 2019 at 9:01
  • @Jens as mentioned its string Commented Feb 9, 2019 at 9:02

2 Answers 2

3

You are trying to convert something to an int and then try to call Toast.makeText(Context context, int resId, int duration). If the second argument is an int, it is expected to be a resource id.

The question is whether you want it to be converted to an int at all. Right now, you're using its value only to show it on a toast message, which in turn expects a string to be passed.

Toast.makeText(this, String.valueOf(minput), Toast.LENGTH_SHORT).show();
Sign up to request clarification or add additional context in comments.

Comments

0

Try This would Fix it :

    temp=editm.getText().toString().trim();
    minput = Integer.parseInt(temp);
    Toast.makeText(this, minput, Toast.LENGTH_SHORT).show();

UPDATE :

It can issue for your toast : (try convert int to string in yout toast message)

Toast.makeText(this, minput.toString(), Toast.LENGTH_SHORT).show();

6 Comments

There is no datatype Int in java
was a misstake i fix it
@AmirRahmamzadeh kho findViewById kardi edittext ro ?
@MoHammaDReZaDehGhani are , hata khode stringesh ro mitonam to Toast mostaghim estefade konam v neshon mide , faghat int nemishe
@AmirRahmamzadeh fek konm toast faghat string migire
|

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.