J2ME Double value Problem - java-me

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)

setString
f+""
means convert it to string while setting in field

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

Related

NumberFormatException when i try to toDouble() the String, even when the input String is a valid representation of a Double

i got an issue with my Code. Im using Android Studio with Kotlin.
So, i got an EditText-field with an input-type="numberDecimal".
when i try to convert that string to a Double:
val preis = etProduktGekauftPreis.text.toString().toDouble()
and try to create a new Object with the "preis"
val produkt = Produkt(name, anzahl.toInt(), preis)
For example im getting the error: NumberFormatException: For input string: "3.00"
The string is a valid representation of a number or not? why do i keep getting this Error?
Thanks for the help :)
Its due to your locale, in german it would be expected to give "3,00" instead of "3.00". You would need to parse the string correctly/differently for example by replacing the comma based on what ever possible locales you support or by removing the comma converting to double then dividing by 100

Value of type 'String' cannot be converted to System.Windows.Forms.Label

I'm a bit of a noob. When I try to build my solution I get this single error and I don't know what to do to fix it.
'Calculate and display cost estimate
decCostEstimate = decFeet * decCostPerFoot
**lblCostEstimate = decCostEstimate.ToString("C")**
I'm not sure what to do. Please help me.
You want to set the Text property of the label, not the label itself
lblCostEstimate.Text = decCostEstimate.ToString("C")
Your code tries to assign a string value to an object of type Label, thus causing the error.
The label is an object from the type Label.
It is not possible to write an object from Type int or string, etc. into an label-object.
To make the label show your result just put the result into the text-property of the label:
lblCostEstimate.Text = decCostEstimate.ToString("C")

Arithmetic operation in jmeter Groovy

I created a script that receives a variable from another sampler.
I put the variable in a new variable (not want to mess with the source).
And I tried to double the result, the problem is that it multiply as a string and not as in math.
The variable is 6, and I wanted to display 12, but it display 6.0 6.0.
Moreover, how can I save the results in a new variable?
System.out.println(" Impression Price *2 is: " + Impression_price*2);
System.out.println(" Impression Price*2 is: " + (Impression_price.multiply(2.0)));
You need to cast your args[3] which is a String to a corresponding numeric type, for example:
def Impression_price = args[3] as float
Demo:
More information: Creating JMeter Variables in Java - The Ultimate Guide
You need to convert String do double using Double.parseDouble, for example:
def Impression_price= Double.parseDouble(args[3]);
When you log you need to convert back to String using String.valueOf, for example:
log.info(String.valueOf(Impression_price*2));
To put a non String value you need to use vars.putObject:
vars.putObject("Impression_price_double", Impression_price *2);

vb.net Unable to keep decimal places when converting string to single

I have been working on a vb.net project and have run into a problem. I have tried various implementations from Stackoverflow and MSDN but nothing is working. All I am trying to do is convert a string value to a single and keep the precision.
An example of the code would be something like this:
Dim Total As Single = 0
Dim s as String = "427.00"
Total += Single.Parse(s)
// Total = 427
// Expected : 427.00 <-- I need this
I have tried using cultureinfo.invariant,
I have tried using string.format,
I have tried using double instead of single,
I don't know what I am missing.
Any insight would be appreciated, and I can provide more code of what the application is trying to do if necessary.
In addition to #Alex B.'s comment, this is how you would achieve this. Total is a String but the program will bomb if either is not a Single type giving you some type safety.
Dim Total As String = "0"
Dim s as String = "427.00"
Total = (Single.Parse(Total) + Single.Parse(s)).ToString("0.00")

String found double expected, lotusscript

In Lotusscript I have this:
Dim PurchaseValue As Double
PurchaseValue = CDbl (docOrder.InkoopKeerAantal(0))
On the form InkoopKeerAantal is a Number.
I get the error:
Type mismatch in method CoerStrToNum: STRING found, Double Expected.
If I do CInt then I get String found Short expected...
And PurchaseValue = docOrder.InkoopKeerAantal(0)
Also gives me the same error as above.
PurchaseValue = docOrder.getItemValue("InkoopKeerAantal")(0) might do it.
My reference was to a wrong document.. Thanks everyone and sorry of this mistake

Resources