Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Java Micro Edition
Search Coderanch
Advance search
Google search
Register / Login
Forums
Register
Login
Mobile
»
Java Micro Edition
problem with double operations
krzys waleski
,
Greenhorn
Oct 16, 2010 08:02:43
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
I have a problem with code. ( My version of
java
is CLDC 1.1, MIDP-2.0)
import javax.microedition.lcdui.*; import javax.microedition.midlet.MIDlet; public class Midlet extends MIDlet implements CommandListener, ItemCommandListener { private static final Command CMD_PRESS = new Command("Press", Command.SCREEN, 1); private static final Command CMD_EXIT = new Command("Exit", Command.EXIT, 1); double[] arg = new double[1]; private Display display; private Form mainForm; TextField wynik; protected void startApp() { display = Display.getDisplay(this); mainForm = new Form("liczenie całki"); mainForm.append("podaj dane:"); StringItem item ; item = new StringItem("", "licz", Item.BUTTON); item.setDefaultCommand(CMD_PRESS); item.setItemCommandListener(this); mainForm.append(item); wynik = new TextField("tu będzie wynik", "", 15, TextField.ANY); mainForm.append(wynik); mainForm.addCommand(CMD_EXIT); mainForm.setCommandListener(this); display.setCurrent(mainForm); } public void commandAction(Command c, Item item) { if (c == CMD_PRESS) { // double dliczba=1.1;// it works**************************************** double dliczba=(1.1+2.2);// it doesn't work!! String h = Double.toString(dliczba); wynik.setString(h); } } public void commandAction(Command c, Displayable d) { destroyApp(false); notifyDestroyed(); } protected void destroyApp(boolean unconditional) { } protected void pauseApp() { } }
The "problematic" code is marked by asteriks.
i got the debug info:
TRACE: <at java.lang.IllegalArgumentException>, Exception caught in Display class java.lang.IllegalArgumentException at javax.microedition.lcdui.TextField.setCharsImpl(), bci=79 at javax.microedition.lcdui.TextField.setString(), bci=37 at Midlet.commandAction(Midlet.java:43) at javax.microedition.lcdui.StringItemLFImpl.uCallKeyPressed(), bci=85 at javax.microedition.lcdui.FormLFImpl.uCallKeyPressed(), bci=87 at javax.microedition.lcdui.DisplayableLFImpl.uCallKeyEvent(), bci=146 at javax.microedition.lcdui.Display$DisplayEventConsumerImpl.handleKeyEvent(), bci=30 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)
Darryl Burke
,
Bartender
staff
Oct 16, 2010 08:25:15
(0 cow)
(0 skulls)
1
+Pie
Number of slices to send:
Send
Background reading:
http://docs.sun.com/source/806-3568/ncg_goldberg.html
double dliczba=(1.1+2.2);// it doesn't work!!
It "doesn't work" because
Double.toString(3.3)
is more than 15 characters in length, and the text field was constructed with a capacity of 15 characters. Add a line and the Exception goes away.
double dliczba = (1.1 + 2.2);// it doesn't work!! String h = Double.toString(dliczba); h = h.substring(0, 15); wynik.setString(h);
Oh, and welcome to the Ranch!
krzys waleski
,
Greenhorn
Oct 16, 2010 08:33:58
(0 cow)
(0 skulls)
+Pie
Number of slices to send:
Send
thanks!!
Post by:
autobot
Switching from electric heat to a rocket mass heater reduces your carbon footprint as much as parking 7 cars. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
reply
This thread has been viewed 1401 times.
Similar Threads
IllegalAccessException
Current focused item in the form
Working with Command Item
Can not connect server socket over internet
Getting Battery Level
More...
All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:04:05
.