Home › Forums › Business Model › Unit Tests › Error: java.util.ArrayList cannot be cast to nexj.core.scripting.Pair
Tagged: ArrayList, core scripting, java
- This topic has 1 reply, 2 voices, and was last updated 8 years, 9 months ago by Ed Shaw.
-
AuthorPosts
-
-
November 21, 2015 at 10:23 am #419ashutoshParticipant
Hi Team,
Can you please let me know why we get below error.
Error: java.util.ArrayList cannot be cast to nexj.core.scripting.Pair
I am have written a method which takes 5 parameters and inserts these parameters in a database table. All the columns in the database are string. I am passing all the 5 parameters as string.
Appreciate any pointers on this error.
Below is the test method:
12345678910111213141516171819202122232425262728293031(define (rbccwm-populate-report ipid pcdid field_name cs_field_value cv_field_value)(display "This is a test for populate record method")(if (= cv_field_value cs_field_value)(RBCReconReport'new(collection(message(: ipid ipid)(: pcdid pcdid)(: field_name field_name)(: cs_field_value cs_field_value)(: cv_field_value cv_field_value)(: stauts_code statusCodeMatch)(: status_message statusMessageMatch))))(RBCReconReport'new(collection(message(: ipid ipid)(: pcdid pcdid)(: field_name field_name)(: cs_field_value cs_field_value)(: cv_field_value cv_field_value)(: stauts_code statusCodeMisMatch)(: status_message statusMessageMisMatch))))))I am calling the method like this
(rbccwm-populate-report “123” “1111222233334444” “Field” “Test” “Test”)
Error:
1234567891011121314151617(rbccwm-populate-report “123” “1111222233334444” “Field” “Test” “Test”)This is a test for populate record method; 18:47:18,380 DEBUG [RBCReconReport] (NexJ-ContainedProcess) Invoking Event RBCReconReport.new(values); 18:47:18,380 DEBUG [GenericREPL] (NexJ-ContainedProcess) Errorjava.lang.ClassCastException: java.util.ArrayList cannot be cast to nexj.core.scripting.Pairat nexj.core.runtime.sys.SysObject.newInstance(SysObject.java:196)at sun.reflect.GeneratedMethodAccessor200.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at nexj.core.scripting.JavaAction.invoke(JavaAction.java:67)at Object.new(values)(class:Object.new(values):1);Error: java.util.ArrayList cannot be cast to nexj.core.scripting.Pairat nexj.core.runtime.sys.SysObject.newInstance(SysObject.java:196)at sun.reflect.GeneratedMethodAccessor200.invoke(Unknown Source)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)at java.lang.reflect.Method.invoke(Method.java:597)at nexj.core.scripting.JavaAction.invoke(JavaAction.java:67)at Object.new(values)(class:Object.new(values):1)Regards,
Ashutosh0 -
November 23, 2015 at 10:57 am #421Ed ShawKeymaster
Ashutosh,
Looks like you have an extra “collection” and “message” in your new statement. When creating a new ReconReport class it should look something like…
123456789(RBCReconReport'new(: ipid ipid)(: pcdid pcdid)(: field_name field_name)(: cs_field_value cs_field_value)(: cv_field_value cv_field_value)(: stauts_code statusCodeMatch)(: status_message statusMessageMatch))Yours looked like
12345(RBCReconReport'new(collection(message(: ipid ipid)...The new event was looking for a pair of an attribute name and a value i.e. (: myAttrib “Hello”) but you were providing it with a “(collection ” which is an ArrayList.
Tip: When looking for documentation on any event, type the event then use CTRL+SPACE
i.e. Type “(RBCReconReport’new ” then CTRL+SPACE. This will give you a list of appropriate class attributes and also help you with the proper syntax. Works great when working with “(message ” as well.Here is the documentation for the Object’new event. You can get this by hovering over it in your code then pressing F2 if you want to scroll through it or copy it.
Object’new
Creates and initializes an instance of this class. The main action is implemented by the framework.@arg values list The list of attribute value pairs to use in creating the new object.
Returns
Object A new instance of the class.Detail
This is a static method and is used to create new objects by specifying their initial values – think of it as the constructor. The ‘create’ method is called by the new method when an instance of the requested object is createde.g. ‘(firstName . “Joe”) ‘(lastName . “Test”)
e.g. (: firstName firstNameParam) (: lastName “Test”)
Example
123(Person'new'(firstName . "Joe") '(lastName . "Test"));Another scheme example of “new” which demonstrates creating a subcollection follows:
1234(Person'new'(firstName . "Joe")'(lastName . "Test")(telcoms . , (instance-collection (Telcom’new ‘(name . “home”) ‘(address . “416-555-1212”))))
); `an alternative – and preferred – syntax to using pairs is the (: operator.
12345(Person'new(: firstName "Joe")(: lastName "Test")(: telcoms (instance-collection (Telcom'new (: name "home") (: address "416-555-1212")))));1- This reply was modified 8 years, 9 months ago by Andrew Penley.
-
-
AuthorPosts
- You must be logged in to reply to this topic.