线程“AWT-EventQueue-1”中出现异常java.lang.NumberFormatException
我的小程序有这个问题。它在产生错误之前只绘制一行。
I have this problem with my applet. It only paints ONE row before it produces the error.
Here's my code: http://www.so.pastebin.com/RkG5YHVQ
Here's the error: http://www.so.pastebin.com/z1qWpFS6
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
只需将
38
行更改为:这将从导致代码错误的数字字符串中删除任何空格。
Simply change line
38
to:This will trim off any whitespace from the number string that is causing the error in the code.
看起来
dan.txt
在零之前包含一个额外的换行符。Looks like
dan.txt
contains an extra newline before a zero.看起来您的扫描仪没有使用空格作为分隔符,并且
Integer.parseInt(src.next());
在它找到的第一个换行符上被阻塞。您可以尝试使用 src.useDelimiter("[,\\s]+") 之类的方法来使用一个或多个空格和逗号字符的任意分组作为分隔符。
Looks like your scanner is not using whitespace as a delimiter, and
Integer.parseInt(src.next());
is choking on the first newline it finds.You could try something like
src.useDelimiter("[,\\s]+")
to use any grouping of one or more whitespace and comma characters as delimiters.以下是开始调试此问题的方法:
自下而上地通读堆栈跟踪并注意 Java 源文件开始出现的位置。对于您的情况:
现在您可以开始使用几种不同的方法来调试该行。首选方法是将调试器附加到正在运行的程序实例,然后查看该行发生了什么。如果您不能这样做,只需添加一个 try catch 块来捕获该代码行周围的异常并打印出实际值与预期值。
Here's how you start to debug this problem :
Read through the stack trace bottom up and notice where your Java source files start to show up. In your case:
Now you can start to debug this line using several different methods. The preferred approach is to attach a debugger to a running instance of your program and see what happens at this line. If you can't do that, simply add a try catch block to capture the exception around that line of code and print out the actual value vs the expected value.