18
Xirate
3y

Gotta love android.

int a;
//do stuff
textView.setText(a);
....
ResourceNotFoundException

Comments
  • 4
    Oh I once forgot to parse an int before using the value for a TextView, guess the system didn't like that lol
  • 13
    Oh cut it with the shit posts...TextView.setText() expects a string to be passed as a parameter, not an integer.
  • 12
  • 1
    @dannydam still, you'd expect a compiler error or at least the runtime error saying that String is expected.
    I do like that you can directly use a resource id, but in a case like this it can definitely cause confusion.
  • 4
    @Bikonja I do think that Google should've added some idiot proofing to setText by making another setText() function in the TextView class that takes int as a parameter and parses it. Nevertheless, anyone who's been programming in Android for more than 5 minutes knows that you're supposed to pass a string to TextView. You can always look up the documentation (Android Studio even has an option to show documentation on mouse hover).
  • 9
    @Bikonja

    I hope to be not mistaken, but Android resources are Integers, that's why the method supports Integers. If you use localization, you'll end up using constants from the resource file, not strings directly.

    Because OOP enables polymorphism and other shit. Please, get your facts straight.
  • 2
    @apex that's exactly what I'm saying, it's nice that there's an overload for resources, but because resources are nothing more than ints you have confusion as there's a chance you might accidentally pass in an int when you wanted to show the actual number, but if resources were standalone objects you'd have a resource overload as opposed to the int overload and then there's far less of a chance for accidental usage of the resource overload.
    Again, I do like the functionality and I agree that after a very short time with Android development you realise your mistake easily, but you can't deny that it's a bit confusing when you first get this situation.
  • 1
    @Bikonja Yeah, for starters you're like "Man, this is awesome", then you understand how everything is wired up and BAM, facepalm to yourself, hahaha
  • 0
    Use Android Studio
  • 0
    @dannydam what is this dumbass language that requires me to explicitly convert an integer to string?
  • 0
    @isaacWeisberg
    For the dumbass developer that does not know what the hell it's doing.

    Just sayin
  • 0
    @apex i am literally asking what's the name of the language
  • 0
    @isaacWeisberg If you're asking for the language the OP it's talking about, it's Java. Otherwise, I don't know what are you talking about
  • 0
    @apex what's Java?
  • 0
    @dannydam It expects string or int (id of resource)
Add Comment