java lang IndexOutOfBoundsException Index 0 Size 0 exception

0 votes

I am getting the error java.lang.IndexOutOfBoundsException: Index: 0, Size: 0.

public Collection<AdDistribution> getAdDistribution(byte srch, byte cont) throws IndexOutOfBoundsException {

    List<AdDistribution> mediums = new ArrayList<>();
    List<AdDistribution> adDistribution = new ArrayList<>();
            adDistribution.add(AdDistribution.SEARCH);
            adDistribution.add(AdDistribution.CONTENT);
            if (adDistribution.isEmpty()) {
                return null;
              }

    if (srch == 0 && cont == 0) {
        mediums = new ArrayList<>();
        mediums.set(0, adDistribution.get(0));
    }
    if (srch == 1 || cont == 1) {
        mediums = new ArrayList<>();
        if (srch == 1) {
            mediums.set(0, adDistribution.get(0));
        } else if (cont == 1) {
            mediums.set(0, adDistribution.get(1));
        }
    }
    if (srch == 1 && cont == 1) {
        mediums = new ArrayList<>();
        mediums.set(0, adDistribution.get(0));
        mediums.set(1, adDistribution.get(1));
    }
            return mediums;
}

Can someone help me fix this?

May 17, 2022 in Java by Kichu
• 19,040 points
2,438 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Java

0 votes
0 answers

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/HasAuthentication

Exception in thread "main" java.lang.NoClassDefFoundError: org/openqa/selenium/HasAuthentication at java.base/java.lang.ClassLoader.defineClass1(Native ...READ MORE

Oct 22, 2021 in Java by anonymous
• 120 points
1,850 views
0 votes
0 answers

Exception in thread "main" java.lang.Error: Unresolved compilation problems

I am facing issues importing classes and ...READ MORE

May 7, 2022 in Java by narikkadan
• 63,600 points
5,523 views
0 votes
0 answers

Getting java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory exception

I am getting this exception when I ...READ MORE

May 18, 2022 in Java by Kichu
• 19,040 points
1,430 views
0 votes
2 answers
0 votes
2 answers

How can I solve java.lang.NoClassDefFoundError in Java?

NoClassDefFoundError means that the class is present ...READ MORE

answered Sep 11, 2018 in Java by Sushmita
• 6,920 points
34,095 views
0 votes
2 answers

how to increase heap size in java?

Here is how you can increase the ...READ MORE

answered Aug 23, 2019 in Java by Sirajul
• 59,230 points
1,873 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 81,222 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
8,357 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
17,432 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points

edited Aug 4, 2023 by Khan Sarfaraz 4,875 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP