0
votes

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)


2

2 Answers

1
votes

setString

f+""

means convert it to string while setting in field

0
votes

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