【发布时间】:2014-09-17 11:31:17
【问题描述】:
我注意到我的程序有一个奇怪的问题,我就是想不通。我已经包含了已标记的方法,以及给出的错误。令我困惑的是,我在其他按钮上重复了这种方法大约 40 次,只在需要时将“engtf4”更改为另一个源。它们完美地工作,没有错误,但写得完全相同。更令人困惑的是,该方法完全按照预期执行(即使给出了下面的错误消息)?
我使用关键字在网上寻找类似的问题 - java.lang.NumberFormatException: 对于输入字符串:“”,但我确实注意到我看到的所有示例网站都引用了 qoute 标记中的特定值。例如,-java.lang.NumberFormatException:对于输入字符串:“2345”。如果能得到任何帮助,我将不胜感激,谢谢。
方法源代码:
if (a.getSource() == engBuy4){
getItems();
q = engtf4.getText();
qq = Long.parseLong(q); //////////// LINE 13086
if (qq > 1000000 || total > 1000000){
Error.setText("You can ship a maximum of 1 million items.");
engtf4.setText("");
}
if (qq <= 1000000 && total <= 1000000){
if (qq > rem){
Error.setText("You can ship " + rem + " more items");
engtf4.setText("");
}
if (qq <= rem){
buyShrEng();
engtf4.setText("");
}
}
错误信息:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at java.lang.Long.parseLong(Unknown Source)
at DopeWars.DopeWars.mouseReleased(DopeWars.java:13086)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
【问题讨论】:
-
LINE 13086- 认真的吗? -
“我在其他按钮上重复了这种方法大约 40 次,只在需要的地方将 'engtf4' 更改为另一个源” - 您可以从重构代码开始。它可以使调试更容易。
-
嗯,阅读错误,很明显 q 设置为空字符串。所以这将很难将其转换为数字。
-
@stuXnet,我使用旧手机作为我的互联网来源,使用此手机传输数据不是那么友好。如果我对下面的示例不满意,我将绕过一个伙伴并使用他们的电脑(如果他们在的话)。无论如何感谢您的选择,非常感谢。没想到会有这么多回应,谢谢大家。
标签: java string parsing jlabel numberformatexception