Runtime Error for loop

for (int i = 1; i<=firstrow.size();i++)
{
dynamic((firstrow.get(i)),-6381922,(addmonth - 1));
}

Error in app:
index: 3, Size: 3

In lists & loops the counting begins with 0 and not 1 so you get the error.

1 Like

i still get the error

this is my full code
for (int i = value_of_i;i!=(value_of_i - (first_days - 1));i--)
{
firstrow.add(i);
}
for (int i = 0; i<=firstrow.size();i++)
{
dynamic((firstrow.get(i)),-6381922,(addmonth - 1));
}
if (addmonth == 2)
{
if ((addyear%2) == 0)
{
twenty_eight_logic = 29;
}
else
{
twenty_eight_logic = 28;
}
}
else
{
twenty_eight_logic = 29;
}
Create(foo,"Label","title");
Component title = COMPONENTS.get("title");
for (int i = 0; i< twenty_eight_logic;i++)
{
((Label) title).Text(String.valueOf(i));
dynamic(i,textcolor,addmonth);
}
if (addmonth != 2)
{
if (value_of_i == 31)
{
dynamic(30,textcolor,addmonth);
dynamic(31,textcolor,addmonth);
}
else if (value_of_i == 30)
{
dynamic(31,textcolor,addmonth);
}
}
for (int i = 0; i < last_days;i++)
{
lastrow.add(i);
}
for (int i = 0; i<lastrow.size();i++)
{
dynamic((lastrow.get(i)),-6381922,(addmonth + 1));
}

Pls help...

What is the type of firstrow? If it's a YailList, you may want to use getObject instead of get as it will handle the 1-based indexing in App Inventor.

As an aside, you may want to edit your posts by using triple backticks ``` on both ends of your code to format it appropriately for the forum.

1 Like

It is an integer list

That's not a Java type. Do you mean that it is a List<Integer>, or that it is a YailList which you expect to contain integers (or some other interpretation)?

In the case of the former, you need to use 0-based indexing in your extension. In the case of the latter, you can use getObject and coerce the result to Integer and let Java unbox it from there.