After running the APP, the APP crashes and reports an error: android.content.res.Resources$NotFoundException: String resource ID #0x1
Error screenshot
Error code segment
Field Type:
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));