Hi ,
I dynamically created the json body . now i am giving the input to field.
for example : i am created multiple same set of field with different value. when tried with count 5 , my code worked . when tried more than 5 , i got this String index out of range: 9
input data :
list of xxCCid= [894607180111007xxxx, 894607180111007xxxx, 894607180111007xxxx, 894607180111007xxxx, 894607180111007xxxx, 894607180111007xxxx, 894607180111007xxxx, 894607180111007xxxx, 894607180111007xxxx]
this is my request : findTestObject(‘CreateOrderRequest/CreateOrder’, [(‘Id’) : GlobalVariable.Id, (‘xyzd’) : GlobalVariable.xyzd, (‘env’) : GlobalVariable.env, (‘subscBody’) : GlobalVariable.subsc, (‘xxCCid’[(count - 1)]) : GlobalVariable.xxCCid[(count - 1)]])
java.lang.StringIndexOutOfBoundsException: String index out of range: 9
at ISL_MultiSaleSale_Max10.run(ISL_MultiSaleSale_Max10:57)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:442)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:433)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:412)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:404)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:281)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1645739362405.run(TempTestCase1645739362405.groovy:25)
Likely, you have an index, count, that is being “filled” from something, and possibly going to index 10 (as you have count - 1). Review how you “fill” the variable, count.
thank you , if i give count 10 ,the error will be “string index out of range:10”. so count is not the issue here …
I add the below code and worked now .but i don’t understand how it is working , i just added while loop without any logic
“”
while(1<=count)
{
count–
}
The first element in a List starts from zero, not 1.
When count comes out of your while loop, it is equal 1. And, “count - 1” therefore is 0. And zero is the first reference in the list.