我用java编一个科学计算器,运行时一按“等于号”(=)就报错,--------------------Configuration:--------------------Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException:For input string:"9=" at sun.misc.FloatingD
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/23 20:18:49
我用java编一个科学计算器,运行时一按“等于号”(=)就报错,--------------------Configuration:--------------------Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException:For input string:"9=" at sun.misc.FloatingD
我用java编一个科学计算器,运行时一按“等于号”(=)就报错,
--------------------Configuration:--------------------Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException:For input string:"9=" at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1224) at java.lang.Float.parseFloat(Float.java:422) at MyCalcular2.actionPerformed(MyCalcular2.java:113) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) at java.awt.Component.processMouseEvent(Component.java:6038) at javax.swing.JComponent.processMouseEvent(JComponent.java:3260) at java.awt.Component.processEvent(Component.java:5803) at java.awt.Container.processEvent(Container.java:2058) at java.awt.Component.dispatchEventImpl(Component.java:4410) at java.awt.Container.dispatchEventImpl(Container.java:2116) at java.awt.Component.dispatchEvent(Component.java:4240) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4322) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3986) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3916) at java.awt.Container.dispatchEventImpl(Container.java:2102) at java.awt.Window.dispatchEventImpl(Window.java:2429) at java.awt.Component.dispatchEvent(Component.java:4240) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:273) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:183) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:173) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:168) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:160) at java.awt.EventDispatchThread.run(EventDispatchThread.java:121)
Process completed.
//其中m是用户输进去的数值和符号,我用stringbuffer的append方法连起来的 String mm=String.valueOf(m); int p1=mm.indexOf("+"); int p2=mm.indexOf("-"); int p3=mm.indexOf("×"); int p4=mm.indexOf("÷"); if(p1!=-1){ p=p1; } else if(p3!=-1){ p=p3; }else if(p2!=-1){ p=p2; } else if(p4!=-1){ p=p4; }
我用java编一个科学计算器,运行时一按“等于号”(=)就报错,--------------------Configuration:--------------------Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException:For input string:"9=" at sun.misc.FloatingD
自己根据提示,找原因
java.lang.NumberFormatException: For input string: "9=" at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1224) at java.lang.Float.parseFloat(Float.java:422) at MyCalcular2.actionPerformed(MyCalcular2.java:113)
很明显,"9="不是数字
在MyCalcular2.java:113行