Displaying integer on toast

16,122

Solution 1

Toast.makeText either takes a CharSequence or an int as its second argument.

However, the int represents a resource ID (such as R.string.hello_world).

The application crashes probably because no resource is found with that ID, since it's not an ID to start with, but an arbitrary integer.

In your case, use Toast.makeText(this,String.valueOf(bignum),Toast.LENGTH_LONG).show();.

Solution 2

you need a String

Toast.makeText(this, String.valueOf(bignum),Toast.LENGTH_LONG).show();

otherwise android will try to look it up for a String with id bignum, in your strings.xml file

Solution 3

Try this to "cast" bignum to string:

Toast.makeText(this,"" + bignum,Toast.LENGTH_LONG).show();
Share:
16,122
Gal Israel
Author by

Gal Israel

Updated on June 20, 2022

Comments

  • Gal Israel
    Gal Israel almost 2 years

    Im trying to display a toast message with integer inside it This is how i tried to do it:

     Toast.makeText(this,bignum,Toast.LENGTH_LONG).show();
    

    But it keeps crash my app. Thanks for help!

    • Kon
      Kon over 9 years
      "Crashes my app" tells us nothing. What exactly happens? What errors are logged? What happened when you debugged?
    • asteri
      asteri over 9 years
      Came for the title, left disappointed.
    • Gal Israel
      Gal Israel over 9 years
      @asteri I'm just starting with java, its my second day..
    • Paul Tomblin
      Paul Tomblin over 9 years
      Even on your second day, we expect you to be able to report what error messages you saw.
    • asteri
      asteri over 9 years
      @GalIsrael It was just a joke. :) Putting Integers on toast, like baked bread. That's all. Wasn't a criticism.