我正在使用此代码:
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
double cTotal1=Double.parseDouble(costdrink.getText());
double cTotal2=Double.parseDouble(jtxtmaterial.getText());
double ctotal3=Double.parseDouble(cost_Delivery.getText());
double altotal = (cTotal1 + cTotal2 + ctotal3);
String itotal = String.format("Rs %.2f", altotal);
jcomtotal.setText(itotal);
}
它不起作用.. 它给出了这些错误,如下所示..
run:
Exception in thread "AWT-EventQueue-0" java.lang.NumberFormatException: For input string: "Rs 15.00"
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1224)
at java.lang.Double.parseDouble(Double.java:510)
at restaurant.Restaurant1.jButton4ActionPerformed(Restaurant1.java:1067)
at restaurant.Restaurant1.access$700(Restaurant1.java:39)
at restaurant.Restaurant1$8.actionPerformed(Restaurant1.java:268)
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.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272)
at java.awt.Component.processMouseEvent(Component.java:6031)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3261)
at java.awt.Component.processEvent(Component.java:5796)
at java.awt.Container.processEvent(Container.java:2056)
at java.awt.Component.dispatchEventImpl(Component.java:4403)
at java.awt.Container.dispatchEventImpl(Container.java:2114)
at java.awt.Component.dispatchEvent(Component.java:4233)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4249)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3913)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3843)
at java.awt.Container.dispatchEventImpl(Container.java:2100)
at java.awt.Window.dispatchEventImpl(Window.java:2438)
at java.awt.Component.dispatchEvent(Component.java:4233)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:597)
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)