Java parseInt NumberFormatException

Java parseInt NumberFormatException,java,numberformatexception,parseint,Java,Numberformatexception,Parseint,我试图通过parseInt将一个数组中的字符串值赋值给一个整数,我得到了这个错误。有什么建议吗 System.out.println(“加载信息的循环中”); 尝试 { 字符串testnumber=“1”; System.out.println(“testnumber的数值为:”+Integer.parseInt(testnumber.trim())); System.out.println(“数组中的字符串值为:“+Global.teamPlayerHandicap[row][0].trim(

我试图通过
parseInt
将一个数组中的字符串值赋值给一个整数,我得到了这个错误。有什么建议吗

System.out.println(“加载信息的循环中”);
尝试
{
字符串testnumber=“1”;
System.out.println(“testnumber的数值为:”+Integer.parseInt(testnumber.trim()));
System.out.println(“数组中的字符串值为:“+Global.teamPlayerHandicap[row][0].trim());
int testvalue=Integer.parseInt(Global.teamPlayerHandicap[row][0].trim());
System.out.println(“测试值:”+testvalue);
}
捕获(数字格式)
{
System.out.println(“这不是一个数字:“+Global.teamPlayerHandicap[row][0].trim()+“END”);
System.out.println(e.getMessage());
}
输出:

in the loop for loading info

Numeric value of testnumber is:1

Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "1"

String value from array is:1

This is not a number:1END

For input string: "1"
    at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
    at java.lang.Integer.parseInt(Integer.java:449)
    at java.lang.Integer.parseInt(Integer.java:499)
    at com.snafilter.TGL.DoWorkTGL1.PopulateSubmitScoresInfo(DoWorkTGL1.java:1271)

尝试使用指定的字符编码

String trimStr = Global.teamPlayerHandicap[row][0].trim();
byte[] bytes = trimStr.getBytes();
String str = new String(bytes, Charset.forName("UTF-8"));

int testvalue = Integer.parseInt(str);
System.out.println(testvalue);

欲了解更多信息,请查看

线程是否存在一些奇怪的情况?看起来这段代码工作正常,但另一个线程抛出了错误。您给出的代码是否确实在DoWorkTGL1.java的第1271行附近?请尝试用
.replaceAll(“[^\\d]”,“)
替换
.trim()
,然后再次运行。天哪……replaceAll返回“Test value:”中的实际值。那么,是不是有些隐藏的东西被加载到了我的数组中,而我的trim并没有将其清除?