Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试过:
int amount = 5; String amountStr = "0x0" + amount; byte newByte = Byte.parsByte(amountStr);
但我明白了java.lang.NumberFormatException: For input string: "0x05"。
java.lang.NumberFormatException: For input string: "0x05"
如果要解析字符串,请使用Byte#decode:
Byte#decode
byte newByte = Byte.decode(amountStr);
否则,您可以直接转换它(如评论中所述)。