无法在资源/可绘制图片中获取图片ID

时间:2018-06-22 00:04:09

标签: kotlin android-instant-apps

我正在从事Google Instant App开发。 在我的应用中,有图像按钮,每个按钮均设置为默认的灰度图像。 当用户打开应用程序时,用户输入一些数值。 基于此,按钮的图像之一将被替换为颜色一。

//after user's input, we know userChoiceInput and which button we need to touch
var userButtonId: String = "btn" + userChoiceInput

val imgBtnId: Int = resources.getIdentifier(userButtonId, "id", packageName)

我需要获取imgBtnId。

如果我在已安装的应用程序版本中运行它,那么我会得到想要的。

但是,如果我在即时应用程序版本中运行,则会得到0 ...这不是故意的。

我可以说的其他信息是我得到了以下例外。

kotlin.TypeCastException: null cannot be cast to non-null type android.widget.ImageButton

这是已知的错误吗?

谢谢。

0 个答案:

没有答案
相关问题