Dictionaries not working on occasion

Sometimes dictionaries seem to be buggy and not work properly. On occasion I will try my program which I utilize the new dictionaries, sometimes it works with no errors and I attempt again on a different occasion and it will give me errors. The code is the same and works, its just sometimes it’ll shoot me a random error when it clearly isn’t.

@peterespo Could you provide a more specific example of when they fail? Example data, code, and an error message would help us better identify the exact issue.

This is the error I get only on occasion, other times it will work properly
error
This seems to be where it is erroring
error2
Here’s the entire image capture of my code

The problem is in your code.
“not found” is a most unhelpful value to return,
if you are going to try to select items from it twice over
even though “not found” is not a list of lists.

You must wrap that section code with a test to pre-check for
that “not found” condition, then avoid those select operations if not found.

Look before you leap.

My program was working last night fine, I try to use it this morning and this is the error I get


I do believe I had a error last night I fixed, but I do not think this is on my end

Hi Peter,

I believe this behavior is probably a bug, not a programming issue as identified by @ABG
@ewpatton said he would look at the issue. It would have been nice if ABG would have provided an example of how he would trap ‘You must wrap that section code with a test to pre-check for
that “not found” condition, then avoid those select operations if not found.’ I think he is ignoring the fact that the key you use is a VALID key.

To make this easier for the developers to identify this behavior, would you share an aia of your project (or another small example, that elicits this behavior) and post it here?

I see a similar issue when using the List look up in pairs Block that on occasion, does not find the correct key / pair when using a key that sometimes works (and occasionally provides a not found). I did a hack, where I re-instantiated the searched List, prior to using the look up in pairs (a block that is similar to your get value for key Block in the Dictionaries).

Regards,
Steve

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
presumptiousLookupinNotFoundText

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

Thanks.
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:

grafik

grafik

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 //.

2 Likes

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.

2 Likes

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.