android.content.res.Resources$NotFoundException: String resource ID Fatal Exception in Main

前端 未结 6 1330
攒了一身酷
攒了一身酷 2020-12-05 01:15

I\'ve been trying to make a simple program that fetches a small random number and displays it to the user in a textview. After finally getting the random number to generate

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 01:56

    You tried to do a.setText(a1). a1 is an int value, but setText() requires a string value. For this reason you need use String.valueOf(a1) to pass the value of a1 as a String and not as an int to a.setText(), like so:

    a.setText(String.valueOf(a1))

    that was the exact solution to the problem with my case.

提交回复
热议问题