Wednesday, 4 October 2017

java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 exception

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



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

List mediums = new ArrayList<>();

List 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;
}

No comments:

Post a Comment

casting - Why wasn&#39;t Tobey Maguire in The Amazing Spider-Man? - Movies &amp; TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...