如何修复readJavaFormatString错误?

时间:2015-10-18 02:51:03

标签: java swing netbeans actionlistener jtogglebutton

我必须使用netbeans GUI构建器进行此分配,因此我只包含了我创建的代码。我没有包含任何预先生成的东西。 我的主要问题是我不知道为什么我的代码会产生如下错误消息:(我不希望任何人阅读每个错误,这只是为了得到一个大概的想法)

at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043) 
at sun.misc.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:2043)
at sun.misc.FloatingDecimal.parseFloat(FloatingDecimal.java:122)
at java.lang.Float.parseFloat(Float.java:451)
at JL_5GUIbuilder.jToggleButton1ActionPerformed(JL_5GUIbuilder.java:201)
at JL_5GUIbuilder.access$400(JL_5GUIbuilder.java:15)
at JL_5GUIbuilder$5.actionPerformed(JL_5GUIbuilder.java:85)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.JToggleButton$ToggleButtonModel.setPressed(JToggleButton.java:308)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
at java.awt.Component.processMouseEvent(Component.java:6525)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6290)
at java.awt.Container.processEvent(Container.java:2234)
at java.awt.Component.dispatchEventImpl(Component.java:4881)
at java.awt.Container.dispatchEventImpl(Container.java:2292)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
at java.awt.Container.dispatchEventImpl(Container.java:2278)
at java.awt.Window.dispatchEventImpl(Window.java:2739)
at java.awt.Component.dispatchEvent(Component.java:4703)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
at java.awt.EventQueue.access$400(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:697)
at java.awt.EventQueue$3.run(EventQueue.java:691)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
at java.awt.EventQueue$4.run(EventQueue.java:719)
at java.awt.EventQueue$4.run(EventQueue.java:717)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

请帮我修复下面的代码。我不知道为什么这是错的,但确实如此,我真的很感激任何建议。到目前为止,我还没有找到任何与我的堆栈溢出问题非常相似的答案。我也没有找到任何我理解的答案。

private void jToggleButton1ActionPerformed(java.awt.event.ActionEvent evt)     {                                               
//calculate revenue
double percent = .2;

//converting adult price to a decimal number
float adultPrice = Float.parseFloat(jTextField1.toString());

//convert number of adult tickets sold to int
int numA = Integer.parseInt(jTextField2.toString());

//converting child ticket price to a decimal number
float childPrice = Float.parseFloat(jTextField3.toString());

//converting to an int
int numC = Integer.parseInt(jTextField4.toString());

//parsing string to a double and multiplying by the cost of an adult ticket to get gross for adult tickets
float grossA = adultPrice * numA;

//getting net amount by taking out movie company cut of 20% from gross
float netA = (float) (grossA * percent);

//calculating gross by parsing strings to doubles and then multiplying
float grossC = childPrice * numC;

//calculating net amount for children tickets sold
float netC = (float) (grossC * percent);

//calculating total gorss for all tickets sold
float totalGross = grossC + grossA;

//calculating total net amount
float totalNet = netA + netC;

textArea1.setText("Total gross adult revenue:" + String.valueOf(grossA) +"\n"+"Total net adult revenue : " + String.valueOf(netA) + "\n" +"Total gross child revenue:" +String.valueOf(grossC) + "\n" + "Total net child revenue : " + String.valueOf(netC) + "\n" +"Total gross revenue of sales : " + String.valueOf(totalGross) + "\n " +"Total net revenue of sales: " + String.valueOf(totalNet));
}

1 个答案:

答案 0 :(得分:0)

你只需要改变

jTextField1.toString()

jTextField1.getText()

以及与jTextField2jTextField3jTextField4

相同的问题