- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是我的取消按钮代码,当我在按“=”按钮之前按下它时,它工作正常,但是在显示最终结果时按“=”之后,然后如果按下“C”按钮,则它显示 java.lang.Cancel 按钮。这里的 lang.NumberFormatException 是一段代码,'convert'&'s'是一个字符串
if(e.getSource() == buttonOp){
convert = Integer.parseInt(txt.getText());
System.out.println("parsing done!");
String choice = e.getActionCommand();
if(choice.equals("x^2")){
txt.setText("");
total = convert * convert;
System.out.println("total is"+total);
s += txt.getText();
}
else if(choice.equals("x^3")){
txt.setText("");
total = convert * convert * convert;
s += txt.getText();
}
else if (choice.equals("=")){
//txt.setText(choice);
// number = true;
number = false;
txt.setText("");
System.out.println("pressed '='");
if(txt.getText().length() > 0){
StringBuilder sb = new StringBuilder(txt.getText());
sb.delete(0, txt.getText().length());
s = sb.toString();
}
s = Double.toString(total);
s += txt.getText();
}
/*else if (choice.equals("+")){
total = convert;
}*/
else if(choice.equals("C")){
System.out.println("pressing C");
if(txt.getText().length()>0){
StringBuilder str = new StringBuilder(txt.getText());
str.deleteCharAt(txt.getText().length()-1);
s = str.toString();
}
txt.setText(s);
}
}
else{
txt.setText(null);
}
txt.setText(s);
}
});
这是我在“=”后按“Ç”得到的输出
parsing done!
total is2601.0
parsing done!
pressed '='
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "2601.0"
at java.lang.NumberFormatException.forInputString(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at cal.Calculator$2.actionPerformed(Calculator.java:95)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.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$500(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$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.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$JavaSecurityAccessImpl.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)
最佳答案
来自异常
....parseInt(Unknown Source)...
...For input string: "2601.0"...
因此,您正在为非 int 格式的值(“2601.0”)调用 parseInt()
。
我认为你的问题就在这里
if(e.getSource() == buttonOp){
convert = Integer.parseInt(txt.getText()); // <<<<
所以要么将其放在更合适的位置(在 if-else 内)或使用 Dobule.parseDouble() ,因为计算器应用程序很可能使用非 int 值。
关于java - 在计算器中按取消按钮 'C' 后出现错误(Eclipse IDE 和 swings),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38814126/
我正在寻找一个编辑器/IDE,它可以为不是专门为它构建的语言提供在编码时很好的功能(例如:能够点击到函数定义)。通过这些,我想到了为非常特定的目的而设计的语言,并且通常只被一个小社区使用。换句话说,那
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
有简单的解释性编程语言,实际上还有控制台 interpreter.exe。 需要按 F5 对语法进行着色、自动完成和执行。 (如果有可能进行“调试”——那就太棒了!) 我从来没有做过这样的事情。 有许
我只是想知道是否有任何可以在我的黑莓上运行的 IDE。我的旧 Palm 有 C 和 BASIC 翻译。 C 板上使用 Palm 的内置文本编辑器,但 BASIC 解释器内置了自己的简单编辑器。 黑莓或
我正在制作一个文件编辑器,并希望为我的用户提供一个不错的 IDE,可以在其中在浏览器上编辑他们的 html/css 文件。是否有任何编辑器与 TinyMCE 类似,但它不是一个所见即所得的编辑器,它更
是否有一个带有集成调试器的D IDE? 最佳答案 Descent可以使用调试器。不完全是您的要求,但是... 关于ide - 是否有一个带有集成调试器的D IDE?,我们在Stack Overflow
每个程序员都知道工具很重要,对于开发人员来说,没有比用于编码的 IDE 更重要的工具了。在过去的几年里,IDE-s 成为标准,在这个领域看到创新并不常见。您可以推荐哪些 IDE 具有创新性,它们引入了
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想改善这个问题吗?更新问题,以便将其作为on-topic
我目前正在学习Ironpython和热爱软件,但我希望从使用notepad ++和cmd.exe继续前进,并尝试使用果汁多一点的东西。 我最近了解到Iron python studio不支持Iron
我主要从事 Java 和 C/C++ 开发,但我开始做更多的 Web 开发(PHP、Rails)和 Eiffel(学习一门新语言总是好的)。 目前,我使用 Eclipse for Java、C/C++
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
是否有 280Atlas (280atlas.com)(免费/商业)的替代品? 其中哪些是成熟的? 最佳答案 您可以使用 nib2cib ,这几乎是相同的想法,但它使用界面构建器(xcode的一部分)
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
IDE 的目标是提高生产力。他们在这方面做得很好。重构、导航、内联文档、自动完成有助于极大地提高生产力。 但是:每个工具都是武器 .相同的 IDE 有助于生成块代码。一些 IDE 功能会导致产生不良代
关闭。这个问题是off-topic .它目前不接受答案。 想改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 关闭 10 年前。 Improve thi
我正在寻找一些功能强大的C / C ++编程环境。实际上,我唯一需要的就是强大的源导航+创建工具。免费或商业都无所谓。我更喜欢一些linux工具,但是它不一定是必需的linux应用。 我需要的是一种具
我刚开始学习 D。有人知 Prop 有自动格式化功能的 D IDE 吗? Eclipse 的 DDT 似乎除了语法高亮之外没有任何其他功能。 最佳答案 我相信,目前 MonoDevelop + Mon
我有兴趣为一个副项目构建一个新风格的 IDE。主要是为了取消类固醇IDE上的普通记事本。我正在为已经尝试过的或者你已经看到(或没有看到)看起来很酷并且在 IDE 中有用的东西寻找一些灵感。我可以解决的
我需要维护一些 VB6 应用程序,并且在涉及枚举名称时遇到了一个奇怪的问题。 VB6 中的 Intellisense 应该工作的方式是,如果我的变量名称被定义为,例如,Dim Abraxis as S
正如标题所说,我看到很多编辑将宏录制作为一项功能吹捧,但自己却找不到利用这些功能的方法。那你能用它做什么呢?您可以记录鼠标移动和/或击键的类型?对外面的人真的那么有帮助吗?具体来说,我处理的 Ecli
我是一名优秀的程序员,十分优秀!