Cannot cast from BigDecimal to String in jasper (weird error //$JR_EXPR_ID=18$) - jasper-reports

I have a jrxml file which has a field of BigDecimal value and when I try to execute the report. I get an error called " Cannot cast from BigDecimal to String in jasper". Im doing the report using ireport 5.6.0, and I get a weird error like this,
1. Cannot cast from BigDecimal to String
value = (java.lang.String)(((java.math.BigDecimal)variable_variable1.getValue())); //$JR_EXPR_ID=18$
<----------------------------------------------------------------------->
2. Cannot cast from BigDecimal to String
value = (java.lang.String)(((java.math.BigDecimal)variable_variable1.getOldValue())); //$JR_EXPR_ID=18$
<-------------------------------------------------------------------------->
3. Cannot cast from BigDecimal to String
value = (java.lang.String)(((java.math.BigDecimal)variable_variable1.getEstimatedValue())); //$JR_EXPR_ID=18$
<-------------------------------------------------------------------------------->
3 errors
I tried to change the expression class. but nothing seems to work. I need the value to get the sum and also as a field.

You have a field e.g $F{ID} with field class=java.math.BigDecimal.As you want to use this field as a string as well as decimal;
You can create two variables variable1 with variable Class=java.math.BigDecimal with Variable Expression as $F{ID}
and create another variable variable2 with variable Class=java.lang.String with Variable Expression as $F{ID}.toPlainString()

When I removed tag "printWhenExpression" for that text field with error, the error did not show again.

Related

how to create a Instant class variable in kotlin with my own timestamp

Till now i was using
val date = Instant.now(Clock.system(ZoneId.of("UTC")))
to generate the instant timestamp.
Now I need to substitute it with the date that I want to specify for example "2021-05-03T00:00:00.000Z". When i insert it as a string into the function, the idea gives me the error "Type mismatch. Required: Instant! Found: String". I can't change the function as I have no such access to it. So i need to somehow turn this date into "Instant!" class.
this is how the function that i can't change looks like
public TimeTZ(Instant timestamp, Boolean isLocal) {
this.timestamp = timestamp;
this.isLocal = isLocal;
}
val date = Instant.parse("2021-05-03T00:00:00.000Z")
Converting a string to an Instant (or other typed value) is called parsing. So use the parse method of Instant.

C++Builder - cannot cast from 'AnsiString' to 'TObject'

I have a problem with converting a string variable to TObject.
I have a query that returns two columns to me. In the first column I have varchar values that I translate into strings, and in the second column I have int values.
I want to fill a ComboBox in this way with these values:
cbx1-> AddItem (DataSet1->DataSet->Fields->Field[0]->AsString, (TObject *) (int) DataSet1->DataSet->Fields->Field[1];
As I refer to the second value which is int type, I receive some bushes, e.g., xD, etc.
By trying to convert this value to string, eg:
String temp = IntToStr (DataSet1->DataSet->Fields->Field[1]);
cbx1-> AddItem (DataSet1->DataSet->Fields->Field[0]->AsString, (TObject *) temp;
I receive an error message:
cannot cast from 'AnsiString' to 'TObject'
I do not know what further I can do to convert this value.
You cannot cast an AnsiString value to a TObject* pointer. You can only cast an integer value, or a pointer value, to a TObject* pointer. AnsiString is neither of those.
You are not retrieving the int value from the 2nd field correctly anyway. Field[1] is a pointer to an actual TField object in the Fields collection. That pointer is what you are trying to store in your ComboBox, NOT the int value that the TField represents.
You need to call Fields[1]->AsInteger to get the int value of the 2nd field, similar to how you use Fields[0]->AsString to get the string value of the 1st field:
cbx1->AddItem(
DataSet1->DataSet->Fields->Field[0]->AsString,
(TObject*) DataSet1->DataSet->Fields->Field[1]->AsInteger
// in C++, using reinterpret_cast is preferred over C-style casting:
// reinterpret_cast<TObject*>(DataSet1->DataSet->Fields->Field[1]->AsInteger)
);
This is no different than the code in your previous question:
cbx1->AddItem("one",(TObject*)1);
You are now just placing the literals "one" and 1 with runtime variables of equivalent types.

How can I use a string to load a variable stored in a .mat-file? [duplicate]

If for instance I have a variable xa=2, and then I construct a string by joining 'x' and 'a', how can I make this new string have the value 2?
xa=2;
var=strcat('x','a');
The result of this is var=xa, but what I want is var=2.
Thank you
Use eval():
var = eval(strcat('x','a'));
It will "evaluate" the string 'xa' and translate it to the value of the variable xa.
Source : MATLAB documentation

Struts 2 - Date instance become String

When I submit the form, input error is occur. JourneyDate is instance of 'Date'. But ,here it become String which is not accepted by the setter and getter.
<s:hidden name="JourneyDate" value="%{JourneyDate}"></s:hidden>
I want JourneyPlan as Date Type, but it become String.
Try intercepting the value before passing it to the getter/setter. For example send JourneyDateString from your form, create a Date from the String, and then pass that to your getter/setter. Something like:
public void setJourneyDateString(String journeyDateString)
{
//journeyDateString could be "2013-03-28" for example
Date journeyDate = new SimpleDateFormat("yyyy-MM-dd").parse(journeyDateString);
setJourneyDate(journeyDate);
}
The object that you've set in the value attribute will keep it's type as Date. Then you need to define corresponding setter in the action to set the value of the Date. It will convert to string if you place the value in the body of the tag.

Ext-gwt (gxt) TextField getFieldValue() problem

I have an TextField with datatype Integer, so I am trying to getFieldValue() and write it to Integer field. So in runtime I have an error here:
TextField<Integer> priceField = new TextField<Integer>();
Integer newPriceFieldValue = priceField.getValue(); //here is an error in runtime
So I cant understand whats the problem - proceField.getValue() should be Integer, why string? Maybe I should another type of Field?
java.lang.ClassCastException: java.lang.String cannot be cast to
java.lang.Integer
at
ru.braginini.client.ProductForm$2.componentSelected(ProductForm.java:64)
at
ru.braginini.client.ProductForm$2.componentSelected(ProductForm.java:1)
If you are expecting only numbers to be used in this field NumberField may be the better choice.
NumberField field = new NumberField();
field.setPropertyEditorType(Integer.class);
It will ensure only numbers are entered, and save you some casting & error handling on the getValue() call.
getValue returns a String!
You want to assign this String to an Integer which causes an CastException (like it would in any Type oriented Programming language.
Try
Integer newPriceFieldValue = Integer.parseInt(priceField.getValue());
Regards,
Stefan