J2ME双值问题

时间:2011-04-19 15:10:08

标签: java-me double textfield midp

执行一些操作后,我无法在TextField中显示double值 处理它。基本上,我只是将Celcius转变为 FarenHeit在转换器应用程序中。 这是代码


   double c = Double.parseDouble(t1.getString());
   double f = c * (9.0D/5.0D) + 32.0D;


Netbeans is giving me the following runtime error

TRACE: , Exception caught in Display class
java.lang.IllegalArgumentException
        at javax.microedition.lcdui.TextField.setCharsImpl(), bci=127
        at javax.microedition.lcdui.TextField.setString(), bci=37
        at ConverterMain.convert(ConverterMain.java:139)
        at ConverterMain.commandAction(ConverterMain.java:66)
        at javax.microedition.lcdui.Display$ChameleonTunnel.callScreenListener(), bci=46
        at com.sun.midp.chameleon.layers.SoftButtonLayer.processCommand(), bci=74
        at com.sun.midp.chameleon.layers.SoftButtonLayer.commandSelected(), bci=11
        at com.sun.midp.chameleon.layers.MenuLayer.keyInput(), bci=290
        at com.sun.midp.chameleon.CWindow.keyInput(), bci=38
        at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handleKeyEvent(), bci=17
        at com.sun.midp.lcdui.DisplayEventListener.process(), bci=277
        at com.sun.midp.events.EventQueue.run(), bci=179
        at java.lang.Thread.run(Thread.java:619)


2 个答案:

答案 0 :(得分:1)

setString

f+""

表示在字段

中设置时将其转换为字符串

答案 1 :(得分:0)

用如此少的代码很难说清楚。 如果我是你,我会添加几个日志,如

System.out.println(t1.getString());
double c = Double.parseDouble(t1.getString());
System.out.println(c);
double f = c * (9.0D/5.0D) + 32.0D;
System.out.println(f);

你确定t1.getString()是一个有效的Double吗? 尝试使用try-catch块