[Solution to the problem] android.content.res.Resources$NotFoundException

After running the APP, the APP crashes and reports an error: android.content.res.Resources$NotFoundException: String resource ID #0x1

Error screenshot
Insert image description here

Error code segment
Insert image description here

Field Type:
Insert image description here

Reason for the error:
Because the type of num and price is int, but the formal parameter in setText() is String, but the value we assign is of type int, it will be mistaken for the resId, so the compiler cannot find the correct resource. Report an error.
Solution:
Just add "" or String.valueOf() to the code to convert the int type into String, and the problem will be solved:

int value = 0;
// 直接加 "" (注意是英文的)
textView.setText(value + "");
// 使用String.valueOf()
textView.setText(String.valueOf(value));

Insert image description here

Guess you like

Origin blog.csdn.net/tuhuanxiong/article/details/114706498