Dictionaries not working on occasion

There have been some previous reports of certain types of keys not working with dictionaries. Fixes have been deployed on http://ai2-test.appinventor.mit.edu. You may want to try using the companion from that server to see if you still have the same issues.

1 Like

I’m ready to be nicer to posts that include .aia files to save me from having to retype blocks from pictures. Meanwhile, I’ll be catching up with the rest of last night’s posts.

Appreciate it, seems to be working properly for me now!

Having looked more deeply at the code, I think the issue is that there is a logic bug in the updateQuestions procedure. This is called from Screen1.Initialize, so at the time it is evaluated the questionValue variable will be 0. This is checked in the if block with two tests, one of which must always be false if the other is true (i.e., questionValue cannot both be < and = to the size of the dictionary). This means that the body of the if block is never evaluated. At this point we proceed into the setter blocks, which attempt to look up the questionValue (which is 0) in the questionList variable. questionList does not have a key 0, so “not found” will be returned. If the logic around the mathematic comparison operators is clarified, then the behavior will be that the if block’s then statements will be evaluated, which increments the questionValue to 1, which is in the dictionary, and things progress from there.

1 Like

notfound_confound.aia (163.8 KB)
I have coded a sample app to illustrate the way to pre-check lookups before diving into them.
Here is the fast food version.
A seven course meal version will (time permitting) appear in an appropriate board section.
Check question Q9 error message

lookupResultTesting notfound error message notfound_confound.aia (163.8 KB) presumptiousLookupinNotFoundText sampleQuestion when btnErrorAnalysis Click when btnErrorHandling Click when btnSampleData Click

1 Like

I posted a self contained tutorial at How to Deal with notfound from lookups
based on my sample app.

I just discovered that dictionary look up fails (not found) if the "key" phrase has a lagging " " (space)

So, use this to remove spaces trim

1 Like

I need the spaces for many phrases to go on.
So, I will also have to add them after the translation with the text block "Join"

Btw, no need to start with // for an image from the assets:



1 Like

But you do need // to read a file from the assets with file component ¿isn't it?

Yes, but this is the only component, that uses (needs) two slashes //.


Only the file component needs the // prefix for assets, and we're hoping to move away from this specialization long term with the new Scope property of the File component.


It also fails if the key text has a leading space.

I tried to show a text file (a user's activity log) arranged to fit like in several columns (date, hour, activity, etc...).

As the text has different lengths (number of characters) in different languages, I thought I could make them fit the columns by adding some spaces to the shorter ones.

But it only works in phrases, if you take care to locate the spaces between words (you can put as many as you need, but not leading nor lagging). Thus it can't be used for a single word (unles you spell it like “w . . . . . o . . . . . r . . . . . d”).

This issue aplies only to the key text in the original language to be translated; there is no problem with leading or lagging spaces in the texts in other languages.

I don't know if there is a technical issue for the space not to be considered as a regular text character, when searching in a list of texts.

I just found an extrange issue (a Runtime Error) when reading a file from assets (with double slashes //) in Android 4.2.2.
It works fine with the companion, and also compiled in another mobiles with Android 4.4.4 and Android 8, but not when compiled in Android 4.2.2.
Both Screen1 and File1 defaultFileScope properties are set to App.
Sin título

That is the file:

Sin título

A guess is 4.2.2 can't handle the tilde in Espanol. Try the csv without the tilde.

But there must be something else.
I removed from the file the "ñ" (and also the "/", just in case), but I still have the Runtime Error

Sin título

Show us what you do with the file text once it arrives from the File, and the exact error message.

I believe the error happens when requesting to read, because I set up a label on top of the screen to track the events and it seems not to read anything.

Please see attached the project and a screenshot:

RunTimeErrorInicialLight.aia (35.0 KB)

Sin título