J2ME双值问题

发布于 2024-11-02 04:28:38 字数 1234 浏览 1 评论 0原文

做了一些操作后,我无法在 TextField 中显示双精度值 对其进行处理。基本上,我只是将摄氏度转换为 转换器应用程序中的 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)


I am not able to display the double value in the TextField after doing some
processing on it. Basically, I am just converting Celcius to
FarenHeit in a Converter Application.
Here is the code


   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)


如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倾`听者〃 2024-11-09 04:28:38

setString

f+""

表示在field中设置时将其转换为字符串

setString

f+""

means convert it to string while setting in field

陪我终i 2024-11-09 04:28:38

这么少的代码很难说清楚。
如果我是你,我会添加一些日志,例如

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 块

It is hard to tell with so little code.
If I were you I would add a couple of logs like

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);

Are you sure t1.getString() is a valid Double?
Try using a try-catch block

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文