tuutoo
发贴: 3
积分: 0
|
于 2006-04-13 16:57
我想用对话框读取用户输入的数,并转为数字赋值给变量!但出问题了:下面是代码,textFeeO是一个textField对象。 public void buttonSetEvt(){ String inputSet=JOptionPane.showInputDialog("设定原始的成本(单位:元/小时)"); try{ Integer numInputSet=Integer.parseInt(inputSet); textFeeO.setText(inputSet); }catch (NumberFormatException e){} }
上面的"Integer numInputSet=Integer.parseInt(inputSet);"如果换成"Float numInputSet=Float.parseFloat(inputSet);"一点“取消"就会出现如下的错误(用Integer没有问题):
E:\Java>java myProject Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at sun.misc.FloatingDecimal.readJavaFormatString(Unknown Source) at java.lang.Float.valueOf(Unknown Source) at subComponent$buttonAction.buttonSetEvt(myProject.java:120) at subComponent$buttonAction.actionPerformed(myProject.java:134) 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 Sour ce) 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.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForHierarchy(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)
tuutoo edited on 2006-04-13 17:05
|