I'm trying to make my application multilingual using the Web1 JsonTextDecodeWithDictionaries block.
The three blocks attached show my solution, which is not good. I get the following error message on my phone when I start my application for the second time: Runtime Error java.lang.String cannot be cast to com.google.appinventor.components.runtime.util.YailDictionary End Application .
How can I solve this problem so that this error message does not appear?
However, I also ask that since I assume that reading the Dictionary JSON file into the application with the Web1 block takes time (especially if there will be more languages in the dictionary), how can I give more time for my Dictionary to be usable in my application?
I have corrected the commands in my application according to your advice. I hope I understood your advice correctly. I am attaching the three questionable blocks.
Perhaps because I don't know the correct value of the file path (string), my application can't find my Szotaram.json dictionary in the File1.Exist block of the Screen1.Initialize section. First, I gave the following value for the file path in a text block: '//' without quotes. Then I deleted it. When this didn't work either, only the following error message "File not found", I inserted the block containing the file name from the Screen1 section in place of the file path. Even then, the part that checks whether the Szotaram.json file exists cannot find my Szotaram.json dictionary. But this only happens the first time I run my application.
When I run my application for the second time, the original error message "Runtime Error ..." appears again, and the values (texts) of some keys of one of the languages from my dictionary are displayed.
Where am I wrong?
It is ironic that your app teaches math functions, but you never use a value function in your app, and never parametrize.
I went looking for where valasztott_nyelv (the current language code) is set in your code, and found a couple of hundred tests of it.
That should have been hidden under layers of value function calls.
I am finding your use of global variables for signalling too complex for me, like a game of Jenga.
I recommend splitting up Clock1.Timer into a few separate well named Clock components with their own simpler single functions. Swiss Army knives are awful.
You could have asked for the TinyDB value at tag 'MyDict', with default an empty dictionary.
Drop it into global MyDict regardless, then test global MyDict against the value Empty Dictionary.
It is always simpler to lose global variables and flags, if you you can get your status information directly. Fewer wires to cross.
The code you want to execute in Screen1.Initialize after you are sure global variable MyDict has been loaded should be moved into a separate procedure, call it Initialize_Phase_2.
You would choose to call it from after you verified that global MyDict is ready, either early in Screen1.Initialize after MyDict came back full from TinyDB, or in the File1.GotText event, after you used the JSON data to load up TinyDB and the MyDict global variable.
I regret your code is too fragile for me to do that for you. I might break something amidst its nest of swords.
Until I know how to make sure that the MyDict global variable is loaded, I will not put the Initialize_Phase_2 part, which would be responsible for displaying the text values of the user interface elements, into a separate procedure.
I am trying this APK file on my phone.
Before installing the next copy after modifying the code, I delete my application data and the application itself (Proportion Solver) from my phone.
The video below shows that the error message appears when I run my application for the first time after installation, but when I run my application for the second time, my application works almost fine. The video of my application.
Now the error message mentioned in the title does not appear when I first run my application, however the text translations of the UI elements are not yet displayed, although a pop-up message indicates that the json file was loaded successfully.
Again, the element texts only appear when I run my application for the second time.
I am attaching a link to the video of the first and second run. Application's first run. Application's second run.