power_settings_new

java.lang.IndexOutOfBoundsException: Index: 1, Size: 1

by (391 points)
+1 vote
621 views
at java.util.ArrayList.rangeCheck(Unknown Source)
    at java.util.ArrayList.get(Unknown Source)
    at pageObjects.LatestArticles.clickArticleLink(LatestArticles.java:133)
    at testCases.VerifyLatestArticles.verifyLoadLatestArticles(VerifyLatestArticles.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:85)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:639)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:816)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1124)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:108)
    at org.testng.TestRunner.privateRun(TestRunner.java:774)
    at org.testng.TestRunner.run(TestRunner.java:624)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:359)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:354)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:312)
    at org.testng.SuiteRunner.run(SuiteRunner.java:261)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1215)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1140)
    at org.testng.TestNG.run(TestNG.java:1048)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:236)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:81)

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

2 Answers

by (171 points)
0 votes
It looks like you are using Array and trying to access certain element.

 

This error occures when array or collection size is lessear then expected.

E.g. when you say String[] values = otherElement.getValues();

You are expecting values size to be 10 and so you try to access values[9] but actual values size is < 10. So no way you have values[9] in place.  In that case you will face above error.

Best way to resolve that is by placing if condition before accessing the value.

 

E.g.

String singleValue;

String[] values = otherElement.getValues();

if(values.length >= 10)

singleValue = values[9];

 

Hope that helps.
by
0 votes

If ArrayList Size = 1 And Index = 1

java.util.ArrayList.get(Index)==> java.lang.IndexOutOfBoundsException

by (171 points)
Array starts from 0. So to get the first array I should be using java.util.ArrayList.get(Index - 1).

Hope that helps.
by
Good:Array starts from 0
add
...