Error: "Select list item: List index too large" and "Select list item: Attempt to get item number 1 of a list of length 0" — Need Help

Hi everyone,
I’m getting these error messages when running my Kodular app:

Select list item: List index too large
Select list item: Attempt to get item number 1 of a list of length 0: ()

It seems that the app tries to access an item in an empty list or with an index larger than the list length.

I am loading data from a file into lists, but it crashes when trying to access the first item.

Please help me understand how to fix this.
Thanks!



Hi dear,

Welcome to the Kodular community!

In both errors you’re selecting a wrong index with select list item, so the mistake must be in one of those blocks.

Here you should use lists_length, not text_length (is used only for strings).

If the error happens when pressing Button1, the error is in num,


which is selecting an index larger than the size of one or more lists.

1 Like

If the file you’re getting is a CSV,

Header1,header2,header3\n
itemA1,itemB1,itemC1\n
itemA2,itemB2,itemC2\n

there is a block that converts it into a list of lists, which is very convenient to work with.
lists_from_csv_table

1 Like

Thank you so much for your help!
Your fix solved the error completely, and now the app loads without showing the “empty list” issue anymore. I also made sure to use length of list instead of length as you advised.

However, I still have one problem:
When I type a word that definitely exists in the wrongword list, the app still jumps to the final “word not found” condition, as if the word isn’t in the list.
So the matching part doesn’t work even though the word is actually there.

If you have any idea what might cause this, I’d really appreciate your help.
Thanks again for your time and support!

Well done, im glad.
Could you briefly explain to me what the whole part regarding button1 consists of? I think the code can be reduced a lot.


image
to compare two words, always use the blocks from the text section (not the solution)
text_compare


If you mean this part of the code, the “wrong word” section is inside a for loop without any if conditions, so for each element of the list it sets LabelResult to “Loaded: …”

1 Like

Here is a brief explanation of what the Button1 logic is supposed to do:

The user types a word into TextBox1, and I store this text as inputWord.
This word already exists exactly in the wrongword column in my list (after loading the CSV).

When the user presses the button, the app should:

  1. Check for an exact match

If inputWord exactly matches an item in the wrongword list,
then I get the corresponding correctword, and also the explanation if it exists.

  1. If there is no exact match → check similarity ≥ 60%

If similarity is ≥ 60 with any wrongword item, I add the corresponding correctword (and explanation if available) to a list of similar results.

  1. If still no match → check similarity ≥ 30%

Same idea: collect all items with similarity ≥ 30.

  1. If none of these conditions succeed

The app should show:
“The word is not found. Try another form.”


What is happening now:

Even when I type a word that definitely exists in the wrongword list,
the app always shows the last message (“word not found”),
as if the exact match is not being detected.

And yes, I confirmed that I used length of exactly as you told me.

Thank you so much again for your help. Your previous suggestion fixed the error, and I really appreciate it.

You are running other code even if inputWord = correctWord, try doing it like this.


Are you sure the similarity function works correctly?

1 Like

Thank you so much for your quick help, I really appreciate it.
I will try your suggestion now and see what happens.

As for your question about the similarity function, I’m honestly not sure if it’s working correctly or not — I’ll test it as well and let you know.

When I tested the app now, nothing is displayed at all after I type the word in TextBox1 and press the button.

1 Like

I tried exactly what you suggested, but still no result shows when I enter a word in TextBox1.
The button doesn’t return anything now.

Almost,
It was fine like that, you just needed to move label.Text inside the condition inputWord = wrongWord.

1 Like

Tell me if a solution like this could work,

Let’s start right away with a procedure kindly offered by the dear :raising_hands:ABG:raising_hands: @Abraham_Getzler from the AppInventor :appinventor: community.

This is an effective method to compare two words, and in the topic there is a guide that explains step by step how it works.

Levenshtein distance


blocks
blocks (4)

This is a compact version of what you did, the only extra thing I added is checking whether correct has been filled with text or whether the list similarWordLE5 is greater than similarWordLE3, if not, I show a message that the word is not there, otherwise I show some notifiers with the result.

Edit:

Since I didn’t really understand what data to enter, I just put random things :rofl:

pear,apple,explanation1\n
kiwi,ananas, \n
coconut,banana,explanation3\n
peanut,nut,explanation4

To adjust how precisely the words should be taken into consideration, you need to lower or raise these values: 5 and 3.

AIA

NoorProject.aia (9.0 KB)

1 Like

Thank you so much for your detailed explanation and effort in helping me.
The method shown in the second picture might not work well for me because my CSV file has more than 700 rows, which makes it a bit complicated. However, I will try to use the dictionary method you suggested.
Since this is my first time trying to build an app, the topic is quite challenging for me, and I have been struggling with this project for a while.
If you happen to have any tutorial videos on YouTube or elsewhere about handling CSV files and using the blocks with them, could you please share the link with me? That would help me understand better.
Again, I really appreciate your help and support — it has been very valuable to me. I will try the approach you recommended and let you know how it goes.

glad to help you

I haven’t found many guides that talk specifically about a CSV, also because there aren’t many related blocks and they’re only used to convert it into a list, but…
If you have any spefic questions about list manipulation, don’t hesitate to open another topic (always check in the community first to see if your question has already been solved).

I wish you a great continuation.

Happy :kodular:oding!

1 Like

Thank you so much for your kind words and support.
I’ll continue working on the app and try to use the methods you suggested.
If I face anything difficult, I’ll post a new topic just like you recommended and wait for your reply.
Thanks again, I really appreciate your help!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.