Hello guys, I have found this error within log file and I am not sure that I understand this error entirely. The app is trying to create Variable (type: string), but for some reason, this time without success. ERROR - GebeurtenisAfhandelen: (1/189) Casix | | Fout bij verwerken (aantal pogingen: 6) | java.lang.StringIndexOutOfBoundsException | String index out of range: 4 | Failed to evaluate expression, error occurred on line 1, character 1 ERROR - GebeurtenisAfhandelen: (2/189) substring($Postcode,0,4) + ' ' + substring($Postcode,4,2) ERROR - GebeurtenisAfhandelen: (3/189) ^ ERROR - GebeurtenisAfhandelen: (4/189) #011at ViewPointServices.lookupAddressViaZipcode (CreateOrChangeVariable : 'Create String variable') ERROR - GebeurtenisAfhandelen: (5/189) #011at ViewPoint_updateWosIntake.updateWosIntakeVullen (SubMicroflow : 'lookupAddressViaZipcode') ERROR - GebeurtenisAfhandelen: (6/189) #011at ViewPoint_updateWosIntake.updateWosIntake (SubMicroflow : 'updateWosIntakeVullen') ERROR - GebeurtenisAfhandelen: (7/189) #011at ViewPoint_updateWosIntake.OpnameNaarViewPoint (SubMicroflow : 'updateWosIntake') ERROR - GebeurtenisAfhandelen: (8/189) #011at ViewPointServices.OpnameDefinitiefViewPoint (SubMicroflow : 'OpnameNaarViewPoint') ERROR - GebeurtenisAfhandelen: (9/189) #011at Opname.OpnameBijwerkenExtern (SubMicroflow : 'OpnameDefinitiefViewPoint') ERROR - GebeurtenisAfhandelen: (10/189) #011at Casix.GebeurtenisOpnameDefinitiefWebservice (SubMicroflow : 'OpnameBijwerkenExtern') ERROR - GebeurtenisAfhandelen: (11/189) #011at Casix.GebeurtenisAfhandelen (SubMicroflow : 'GebeurtenisOpnameDefinitiefWebservice') ERROR - GebeurtenisAfhandelen: (12/189) #011at Casix.GebeurtenisAfhandelenAanroep (SubMicroflow : 'GebeurtenisAfhandelen') ERROR - GebeurtenisAfhandelen: (13/189) #011at Casix.GebeurtenissenAfhandelen.nested.842973ba-3cdc-42b8-bd4c-88e747f41154 [0 of 1] (SubMicroflow : 'GebeurtenisAfhandelenAanroep') ERROR - GebeurtenisAfhandelen: (14/189) #011at Casix.GebeurtenissenAfhandelen (NestedLoopedMicroflow : '') ERROR - GebeurtenisAfhandelen: (15/189) ERROR - GebeurtenisAfhandelen: (16/189) Advanced stacktrace: ERROR - GebeurtenisAfhandelen: (17/189) #011at com.mendix.languages.mxexpressions.MxExpression.evaluate(MxExpression.scala:15) ERROR - GebeurtenisAfhandelen: (18/189) ERROR - GebeurtenisAfhandelen: (19/189) Caused by: ERROR - GebeurtenisAfhandelen: (20/189) com.mendix.languages.expressions.ExpressionException: com.mendix.languages.expressions.ExpressionException: java.lang.StringIndexOutOfBoundsException: String index out of range: 4 ERROR - GebeurtenisAfhandelen: (21/189) #011at com.mendix.languages.expressions.Expr.evaluate(Expr.java:28) ERROR - GebeurtenisAfhandelen: (22/189) Does anyone has any idea what could be the reason for this error? Thank you in advance.
asked
David Mandic
2 answers
2
The length of the substring you are trying to get is longer than your string. So: you try to get four characters, but if your string only has two characters, you will get this error. You should validate if the length of the string is at least as long as the length of the substrings you are trying to get from it. In this specific case, you should validate length($Postcode) >= 6.
answered
Rom van Arendonk
0
When using the Java substring() method, a subset of the character sequence can be extracted from a string. The substring index must be any value from 0 to the length of a string. The java.lang.StringIndexOutOfBoundsException thrown by String methods to indicate that the beginIndex is negative , or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.
How to solve the StringIndexOutOfBoundsException
Check the length of the string before using substring()