Alternative for AnyLogic deprecated method getJComponent()? - java

I recently updated to AnyLogic PLE 8.4.0 and Java SE 12 on my Windows 10 laptop. And now an AnyLogic model that used to work earlier stops with the error "The method getJComponent() is undefined for the type ShapeTextField." I looked it up in AnyLogic/Help and I notice that getJComponent is identified as "Deprecated" and no alternative is identified. It appears to me that some mismatch happened between AnyLogic and Java updates that resulted in this error. I would appreciate any workarounds to get the model working.
Tried replacing getJComponent() with the following:
by getX() - gave error "cannot cast from double to Jtextfield"
by getPresentable() - gave error "cannot cast from Presentable to Jtextfield"
by getClass() - gave error "Description: Cannot cast from Class to JTextField."
by getComponentGraphics() - gave error "Description: The method getComponentGraphics() is undefined for the type ShapeTextField."
by equals - gave error "Description: The method equals(Object) in the type Object is not applicable for the arguments ()."
The code is:
((JTextField)(editbox.getJComponent())).setHorizontalAlignment(JTextField.LEFT);
This is defined in Simulation - Simulation Experiment / Java Actions/ Initial Experiment Setup field
Expected result: No error message. And the model should proceed to run window.

Thanks to the inputs from #Benjamin and #Felipe the following worked:
I replaced the editbox and buttons with corresponding artifacts from
AL8.4 palette. I copied the code from the earlier artifacts to
corresponding fields in the new artifacts. I deleted the artifacts
that were from AL7.
I commented out the line that was meant to align the editbox since
that capability is not available anymore.
With the above two changes I didn't get the error message about undefined method. The editbox and buttons worked and allowed me to enter XML filename and reading it with an XML parser routine. I have now run into issue with JAXB integration with AL8.4 and haven't been able to get past that yet. I will be posting that as a separate question.

Related

Standard Method TEXT is undefined when compiling jasper report

When I package my stand-alone-java-application, that compiles, renders and prints Jasper-Reports, in a fat jar with all dependencies, I get the error that the function TEXT – a function used in the report and defined in the net.sf.jasperreports-functions-library is not found.
The method TEXT(Integer, String) is undefined for the type [...]
value = IF(LEN(TEXT(((java.lang.Integer)parameter_X.getValue()),"#"))==2,"***",REPT("*",6-LEN(TEXT(((java.lang.Integer)parameter_X.getValue()),"#")))) //$JR_EXPR_ID=58$
Other functions from the same library work. When I run the application with gradle run, the function is found and the report can be printed. The library is on my classpath.
There are several similar questions on this site and Stackoverflow, but neither provided answers, that worked for me. In the following, I will explain what I tried:
In my build.gradle-File I defined dependencies to the following libraries:
implementation('net.sf.jasperreports:jasperreports:6.18.1')
implementation('net.sf.jasperreports:jasperreports-functions:6.18.1')
In my java-Files, I created a DesignFile and statically imported the functions into it. I tried two methods:
Method 1 as given in an answer in this thread: Unresolved symbols when compiling jasper report
/*…*/
designFile = JRXmlLoader.load(sourceFile.getAbsolutePath());
designFile.addImport("static net.sf.jasperreports.functions.standard.TextFunctions.*");
designFile.addImport("static net.sf.jasperreports.functions.standard.MathFunctions.*");
designFile.addImport("static net.sf.jasperreports.functions.standard.DateTimeFunctions.*");
designFile.addImport("static net.sf.jasperreports.functions.standard.LogicalFunctions.*");
JasperReport compiledReport = JasperCompileManager.getInstance(ctx).compile(designFile);
/*…*/
Method 2: importing each function on its own
public static String[] textFunctions(){
return new String[]{"BASE", "CHAR", "CLEAN", "CODE", "CONCATENATE", "DOUBLE_VALUE",
"EXACT", "FIND", /*"FIXED", */"FLOAT_VALUE", "INTEGER_VALUE", "LEFT", "LEN", "LONG_VALUE",
"LOWER", "LTRIM", "MID", "PROPER", "REPLACE", "REPT", "RIGHT", "RTRIM", "SEARCH", "SUBSTITUTE",
"T", /*"TEXT",*/ "TRIM", "UPPER"};
}}
/*…*/
designFile = JRXmlLoader.load(sourceFile.getAbsolutePath());
for (String textFunction : textFunctions()){
designFile.addImport("static net.sf.jasperreports.functions.standard.TextFunctions." + textFunction);
}/* similarly for logical functions, numeric functions and datetime functions*/
}
JasperReport compiledReport = JasperCompileManager.getInstance(ctx).compile(designFile);
/*…*/
As you can see, the function TEXT is commented out. That’s because the program fails at runtime when run with “gradle run”, when I comment it in:
net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The import net.sf.jasperreports.functions.standard.TextFunctions.TEXT cannot be resolved
import static net.sf.jasperreports.functions.standard.TextFunctions.TEXT;
The same thing is true with most datetime-functions, in fact, only TIME can be imported to the DesignObject without error at runtime
In addition to that, when I type net.sf.jasperreports.functions.standard.TextFunctions. in my IDE, the content-assist shows a list of available functions, yet TEXT is missing.
I suspected, that the function is simply missing in the library, but it is there. In the .gradle/cache/modules-2/files-2.1/… directory, there is the jar with the TextFunctions.java, that contains the function TEXT:
When building the FatJar with dependencies, I have a TextFunctions.class-File in it, that contains the TEXT-Function as well.
In my jar, there are two jasperreports_extension.properties on the root level:
with the smaller one (from the jasperreport-functions-dependency) containing the following lines:
net.sf.jasperreports.extension.registry.factory.functions=net.sf.jasperreports.functions.FunctionsRegistryFactory
net.sf.jasperreports.extension.functions.datetime=net.sf.jasperreports.functions.standard.DateTimeFunctions
net.sf.jasperreports.extension.functions.math=net.sf.jasperreports.functions.standard.MathFunctions, net.sf.jasperreports.functions.standard.LogicalFunctions
net.sf.jasperreports.extension.functions.text=net.sf.jasperreports.functions.standard.TextFunctions
net.sf.jasperreports.extension.functions.report=net.sf.jasperreports.functions.standard.ReportFunctions
Funnily enough, commenting out TEXT, running it locally with gradle run, it works without problems. But packaging it and running it with java -jar it fails to find this function. And statically importing this function leads to gradle run failing as well.
What is happening and how can I fix this? I want to distribute my FatJar on a server and run it, but this problems makes it impossible for me.

Java 8 documentation Date-time tutorials mistake

The Oracle Tutorial page for the Temporal Query show this example code.
- Code
TemporalQueries query = TemporalQueries.precision();
System.out.printf("LocalDate precision is %s%n",LocalDate.now().query(query));
When I compile this segment code, the Compiler throws the error:
- Error
TemporalQueryExample.java:8: error: incompatible types: TemporalQuery<TemporalUnit> cannot be converted to TemporalQueries
TemporalQueries query = TemporalQueries.precision();
^
TemporalQueryExample.java:10: error: no suitable method found for query(TemporalQueries)
LocalDate.now().query(query));
^
I don't know this java 8 documentation tutorial example is correct or not but I copy this code segment and paste my IDE then IDE throw the Error.
There is an error in the code. Look at what Lokesh has mentioned.
To further learn coding, make sure you understand the error properly. It will make your life easier. In this example, the error says: TemporalQuery<TemporalUnit> cannot be converted to TemporalQueries
If you check your code, <TemporalUnit> is not there, which is an indication that you have to place it somewhere and the right place to have it is mentioned by Lokesh.
You can go through this tutorial
Change this line TemporalQueries query = TemporalQueries.precision(); to this TemporalQuery<TemporalUnit> query = TemporalQueries.precision();
You can check this Java 9 documentation

Run an ABCL code that uses cl-cppre

With reference to my previous question,
Executing a lisp function from Java
I was able to call lisp code from Java using ABCL.
But the problem is, the already existing lisp code uses CL-PPCRE package.
I can not compile the code as it says 'CL-PPCRE not found'.
I have tried different approaches to add that package,
including
1) how does one compile a clisp program which uses cl-ppcre?
2)https://groups.google.com/forum/#!topic/cl-ppcre/juSfOhEDa1k
Doesnot work!
Other thing is, that executing (compile-file aima.asd) works perfectly fine although it does also require cl-pprce
(defpackage #:aima-asd
(:use :cl :asdf))
(in-package :aima-asd)
(defsystem aima
:name "aima"
:version "0.1"
:components ((:file "defpackage")
(:file "main" :depends-on ("defpackage")))
:depends-on (:cl-ppcre))
The final java code is
interpreter.eval("(load \"aima/asdf.lisp\")");
interpreter.eval("(compile-file \"aima/aima.asd\")");
interpreter.eval("(compile-file \"aima/defpackage.lisp\")");
interpreter.eval("(in-package :aima)");
interpreter.eval("(load \"aima/aima.lisp\")");
interpreter.eval("(aima-load 'all)");
The error message is
Error loading C:/Users/Administrator.NUIG-1Z7HN12/workspace/aima/probability/domains/edit-nets.lisp at line 376 (offset 16389)
#<THREAD "main" {3A188AF2}>: Debugger invoked on condition of type READER-ERROR
The package "CL-PPCRE" can't be found.
[1] AIMA(1):
Can anyone help me?
You need to load cl-ppcre before you can use it. You can do that by using (asdf:load-system :aima), provided that you put both aima and cl-ppcre into locations that your ASDF searches.
I used QuickLisp to add cl-ppcre (because nothing else worked for me).
Here is what I did
(load \"~/QuickLisp.lisp\")")
(quicklisp-quickstart:install)
(load "~/quicklisp/setup.lisp")
(ql:quickload :cl-ppcre)
First 2 lines are only a one time things. Once quickLisp is installed you can start from line 3.

setVerboseLoggingEnabled(boolean) is undefined for the type Cast.CastOptions.Builder

I am using the CastCompanionLibrary-android and it is throwing the following error all of a sudden. Any ideas ?
The method setVerboseLoggingEnabled(boolean) is undefined for the type
Cast.CastOptions.Builder VideoCastManager.java
/CastCompanionLibrary-android/src/com/google/sample/castcompanionlibrary/cast
Its shows taht this method does infact exist in :
http://developer.android.com/reference/com/google/android/gms/cast/Cast.CastOptions.Builder.html
But when I drill into CastOptions it is no longer there.
Its seems I did an update with the Android SDK manager, but neglected to replace the old jar with the newly update jar.
Did this and it fixed the issue :)

Change to compiler 1.7 when creating a List produced errors throughout the entire project

I am using Eclipse Juno and Java.
I was trying to create a new list:
List myList = new ArrayList();
This had an error and the resolution on it was along the lines of change compiler to 1.7 which I accepted. The errror on this list creation line was corrected however I now have many errors thoughout the whole project on lines that were previously working. Some examples are:
class GetAccountAndCubsHandler<T> implements AsyncCallback<List<AccountAndCubs>>
Multiple markers at this line
- The hierarchy of the type GetAccountAndCubsHandler is inconsistent
- List cannot he resolved to a type
public class AccountCreationView extends Composite {
Multiple markers at this line
- The hierarchy of the type AccountCreationView is inconsistent
- Breakpoint:AccountCreationView
#SuppressWarnings("unused")
private String accountId;
First line - Multiple markers at this line
- SuppressWarnings cannot be resolved to a type
- The attribute valie is undefined for the annotation type SuppressWarnings
Second line - String cannot be resolved to a type
As you can imagine having my whole project adversely affected in this way is very disconcerting so any advice on how to recover would be greatly appreciated.
Regards,
Glyn
"String cannot be resolved to a type"
Ensure that a valid JRE or JDK is specified in your build-path.
Since you're using Eclipse, right-click on your project, then Properties → Java Build Path.
Perhaps you don't have a Java 7 JRE configured in the Installed JREs preference panel.

Categories

Resources