"Index out of bounds. Index 0 for empty list."

"Index out of bounds. Index 0 for empty list."

  

What does this usually mean? Strangely, OutSystems says my module is valid.

Hello YS Yeo,

Means you are trying to use information from the row number 1 when your list is empty.

Hello YS Yeo,

I think you are trying to access index 1 of empty list(like below image) that`s why getting this error. Please place a validation(GetCountryTests.Count > 0) to make sure list should have data before accessing the index.



Reagrds

-SK-

Hi YS Yeo,

As stated in the above answers, the error you are facing is related with the fact of you are accessing the value of a position in an empty list.

Related to fact that your module is valid, the error you have happens at runtime (i.e. while you are using your app). For OutSystems, a module is valid when it has no errors at compile time. An out-of-bounds exception isn't detected at compile time.

Cheers,

António Pereira

Thanks. But I do not understand why my list/row is empty.


What I did:

I uploaded my sheet from Excel, then published it (before adding any widgets/values/variables) to make sure my data exists in run time. This is what I see when I click "view data":


Questions:

How do I achieve a non-empty list/row in run time? How do I get my sheet data (which exists in Excel and in compile time) to exist in run time?

Hi YS Yeo,

Please use the action OnInitialize from the mobile screen to load the data before you use it.

Also you can add one condition in your page that check if list is empty or not. If list is empty, don't use that element from the index and show empty space or "-".

Thanks and Regards,

Suraj Borade

Suraj Borade wrote:

Hi YS Yeo,

Please use the action OnInitialize from the mobile screen to load the data before you use it.

Also you can add one condition in your page that check if list is empty or not. If list is empty, don't use that element from the index and show empty space or "-".

Thanks and Regards,

Suraj Borade


Okay Suraj here's what I did:

  1. Interface tab > click my screen > look under "events" > click the dropdown next to "on initialize" > add a new client action
  2. Drop a "get entity" in the client action (see image)
  3. Set "Sheet1Id" as the argument id (see bottom-right of image)

Is that correct? Haha


Hi YS Yeo,

Your database has data, but you need to read it before you can use it. Can you answer a few questions, we might be able to better help you if we understand:

  • What are you trying to achieve?
  • What have you done (implemented)? In particular, why are you trying to access explicitly the second position of a list and how did you get that list in the first place?
  • Where are you getting this error? (at what point in your Mobile Screen/Client Action/Server Action is that error happening)
  • Finally, and out of curiosity, have you followed the online training for Developing OutSystems Mobile Apps?

Jorge Martins wrote:

Hi YS Yeo,

Your database has data, but you need to read it before you can use it. Can you answer a few questions, we might be able to better help you if we understand:

  • What are you trying to achieve?
  • What have you done (implemented)? In particular, why are you trying to access explicitly the second position of a list and how did you get that list in the first place?
  • Where are you getting this error? (at what point in your Mobile Screen/Client Action/Server Action is that error happening)
  • Finally, and out of curiosity, have you followed the online training for Developing OutSystems Mobile Apps?


Hey Jorge, here's what I'm trying to achieve + how I plan to achieve it, detailed clearly with sketches:

And I have yet to complete that online training! Thanks, will do so asap. I have been reading the documentation all the while.

Hi YS Yeo,

Thanks for the nicely laid out information!

From what I can see, Sheet1 is an Entity with two Attributes: a Question (Text?) and an Answer (Integer? Text? cannot be Boolean as you want to keep track of three possible answers).

If you want to display all Sheet1, then an Aggregate is the right choice to read them, but accessing them by indexing the resulting List is not the best approach (as you by now know, with that 'Index out of bounds' error).

I'd say you can use a Table Records on your screen to show your list, this widget iterates through a list (the output of your Aggregate) and YourTableRecords.List.Current.Sheet1 will have the values for the row currently being iterated (no need for indexes). If the Aggregate returns no results, the Table Records will just display a simple text message stating that (and likely means you have some wrong data on your database?).

Note: This sort of thing is covered in classroom training (which I highly recommend you to attend) and also the online training if it's impossible to attend a boot camp, and I assure you going through it earlier will save you a lot of time and painful experiences like the current one...