2011-04-19 93 views
0

在對其執行一些 處理後,我無法在TextField中顯示double值。基本上,我只是將轉換器應用程序中的Celcius轉換爲 FarenHeit。 下面是代碼J2ME雙精度值問題

 

    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) 


回答

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()是一個有效的雙? 嘗試使用try-catch塊

1

了setString

f+"" 

手段將其轉換爲字符串,而在現場

設置