Property setter was expecting a com.google.appinventor.components.runtime.Switch component but got a String instead

I have a screen with some switches and I want the switches on to be saved and appear on when the screen is loaded later. To do so they are added to a list which is stored in TinyDB. When the given screen gets initialized, TinyDB is called and each item (which should be a component) in that list is switched on.

The problem is that apparently the switches are saved as strings and not as components. What can I do?

added_switches
When any switch is switched on, it's saved in a given list.

stored_switches
Then the given list is stored in TinyDB.

list
There are 7 lists for each day of the week (which is chosen on another screen).

switches
When the screen is initialized, TinyDB is called and each item (which should be a component) is switched on.

As far as I know, we can't save component IDs, because each time the app is launched, components have new IDs generated. Instead, build a dictionary with all the switches you have in your app. The key is e.g. Switch1, value true or false. Change and read values.

3 Likes

Thank you, but I didn't manage to make it work. The keys are strings. How should I do it?

You need to make a list of your switch components, and select these in your list iterations

image

1 Like

Fixed. Thank you!

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