B4J Question calculated field in a jasper report

afields

Member
Licensed User
hello to all!
i'm having a strange behavior when i use a jasperreport in b4j.
if the report does not have any calculated field then all is working (even with query parameters).
however if in the report i have a calculated field (whatever it is like for exemple have a field in the report as =10, just that) then when i run the report in b4j i've got several errors.
But if i run the report in jasperStudio all is fine.
thanks!
 

afields

Member
Licensed User
i must say that i had used jJasperReports (1.20) and as additional jar jasperreports-6.7.1.
the messagwes are:

B4X:
main._btnmysql_action (java line: 139)
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. Type mismatch: cannot convert from int to Object
                value = 10; //$JR_EXPR_ID=8$
                        <>
2. Type mismatch: cannot convert from int to Object
                value = 0; //$JR_EXPR_ID=9$
                        ^
3. Type mismatch: cannot convert from int to Object
                value = 10; //$JR_EXPR_ID=8$
                        <>
4. Type mismatch: cannot convert from int to Object
                value = 0; //$JR_EXPR_ID=9$
                        ^
5. Type mismatch: cannot convert from int to Object
                value = 10; //$JR_EXPR_ID=8$
                        <>
6. Type mismatch: cannot convert from int to Object
                value = 0; //$JR_EXPR_ID=9$
                        ^
6 errors
.
    at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:206)
    at net.sf.jasperreports.engine.JasperCompileManager.compile(JasperCompileManager.java:357)
    at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:617)
    at com.prusb.jasperrep.JasperReports.CompileXML2(JasperReports.java:167)
    at b4j.example.main._btnmysql_action(main.java:139)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.BA$1.run(BA.java:216)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
 
Upvote 0

Juan Marrero

Active Member
Licensed User
Longtime User
I've had this situation not only in Jasper but also in Crystal. The error says that is a conversion type error. Like if you declared variable "value" as object or didn't declared a variable type to it and then you are trying to assign and integer to that variable. While you are in the software (Jaspersoft Studio or Crystal Reports) that creates reports it solves automatically different variable types if it can be converted to another type. For example, if you pass a text that is a number, most of the time the software accept it, but outside the software (like in B4J) it doesn't accept it. I can't guarantee that I will look into it ASAP because that would be a lie. I'm going to give it a look later, and hopefully give you a answer soon enough.

Visual Basic auto convert variables when it can be converted. However C# or Java does not auto convert variables to another type even if both values are the same (10 or "10" e.g.)
 
Upvote 0

afields

Member
Licensed User
thank you very much! sir
i want to print lines in diferent colors ( like the old continuios paper ) and for that i use a line count. Each time that variable ( which do not appers in the lines) is odd that a format colour line is use.
The error example was only a test in which a declare a variable in Jr and inicialize it with 10. like you say, in Jr all's fine but not in b4j.
Thank you!
 
Upvote 0
Top