Select list item: Attempt to get item number 1 of a list of length 0: ()

Hi Koders,
I was making a Profile app in which the user adds their image and name to the app.
The list is made with the help of Dynamic Components extension by yusufcihan.
I have also used a extension for circular image which is Leo Profile by DeveloperLeo

In this app in am getting an error as
Error
Which is a well known error.

Though the error is appearing in the companion all is working.
The more items I add in the list the more the error lines are increasing.
This errors are commonly image address which I am retrieving from Firebase and putting them into the list by setting the image from the URL.
These errors are only appearing when I am trying to add the URL to the Firebase.

For more brief explanation
As you can see, there are 3 items in the list


But I am getting the error as

Select list item: Attempt to get item number 3 of a list of length 2: (2 image URL)

Blocks

The Name is working good, there are no errors about that so I guess that there is a problem with LeoProfile Extension while selecting.

But in the APK there is other problem while appending
I tried one time in APK
Error message
Select list item: List index too large
Select list item: Attempt to get item number 4 of a list of length 3: (3 image URL)
End Application

Errorr.aia (249.0 KB)
Errors.apk (6.2 MB)

I have already gone through some topic on this.

Instead of posting the aia/apk, post the related blocks.
No one has enough time to load the aia in the creator and check on the error.

Oh sorry,
I forgot to add the blocks,

Use ‘Do it’ and check if the lists global CI and global CN are equal in length or not?

Try this

Ur image lost lenght is not equal to ur other list

@Vaibhav

Yes they are equal.
Check out the Activity I did.

@dora_paz,
I had thought about it but it won’t work.
For example there are 2 users online.
The first user adds his profile but only for him he gets value but for other user it will not be updated.

@iamwsumit
No the both lenghts are equal.
Check out the Activity I did.

As many koders where telling that it was not equal so i did an activity.
I placed two labels.
And set the blocks as this
Help
And The result I got is

But nevertheless the error continued.

but here is clear
the error is showing your image list contains only 3 item

As you can see in that activity, the length of both the list is 4 but the error is telling that one list contains 4 items and the other list has 3 items.
That’s what I am confused.

If error is coming then how it has created

Though the Error is appearing everything is working fine and good

When data changed or got value then set global ID value is 0.

:thinking: how can it possible

Unfortunately it did not work.

Finally found the Solution,
Thanks all for your cooperation to help me out.

The problem was that Firebase Appends value differently.
I think the list of Firebase (Append) and the list in Kodular are different.
I first add the item to the list then I stored the value.

Any other Koders having the same issue then use this Solution.

#off-topic
By the way the APK runs slower than the Companion in Retrieving the Values.

1 Like

Sorry Koders,
That was not the Solution.
I just changed few Blocks of working AIA and it again started giving the same Error.
I don’t know why the Error is still appearing.
But its working in another AIA.
I tried to debug the Blocks by many ways but none of them worked.

Blocks

Not Working


Double Tap for Best Display

Working


Double Tap for Best Display

I tried to solve out the solution many times but none of the methods worked.

generally before selecting an item from a list make sure, the list is long enough

use Do it to debug your blocks, see also tip 4 here App Inventor: How to Learn | Pura Vida Apps
see also Live Development, Testing, and Debugging Tools
Taifun

1 Like

@Taifun,
Thanks for your Reply.
If you notice my Blocks I have set the length of the 3 list in 3 separate Labels and all the values are same.
All are working even the Items are working fine but only the errors are appearing.

Not a solution, just something I noticed in your code.

Took me long to see it but you have CN two times, so you can’t be sure that the values are really that length. I’m still looking if there is that same mistake somewhere else, but change this one also.

1 Like

I have an idea but I don’t know if it will work.

You call Firebase for the value of “CN”, “D” and “CI” at the same time but the app probably doesn’t receive them at the same time and each times it get the value from firebase, the block with for each number gets called no matter what.

What I had in mind is adding a if statements.

If length of list CN = length of list CI = length of list D 
do 
for each number from 1 to the length of list CN
//add what you want here.

If this one doesn’t work, they calling the data when the other one receives it value. It will be like this:

When screen initialize
Call firebase get value, tag = CN

When firebase1 get value
If tag = CN
    Then: 
     set global variable CN to value
     Call firebase get value, tag = D

 If tag = D
     Then: 
      set global variable D to value
      Call firebase get value, tag = CI

If tag = CI
       Then:
       set global variable CI to value
       For each number from 1 to length of list CN
       do
       //what you want here

I don’t know if this will work at 100% but give it a try and let me know.