Android Question "The given key was not present in the dictionary" error

aedwall

Active Member
Licensed User
Longtime User
What the heck is this and how do I fix it?

What key? What dictionary?

I have a working .b4A project using v13.40. I make some changes, in order to get rid of a problematic dialog2 library and instead use the dialog library. I try to load my new .b4A file and all I see is this error message, along with a start project with none of my files or libraries enabled (the new "project" says "#ApplicationLabel: B4A Example". They are visible, but all grayed out. No matter what I have tried, I can't get .b4A to show my code - it just shows a new example project.

Can anyone shed light on this? I am at the end of my rope. Thank you.
 

aeric

Expert
Licensed User
Longtime User
It seems your .b4a file is corrupted.
You need to
1. create a new project
2. open the b4a file using notepad
3. move your old code to the new b4a file
4. replace the old file with the new b4a file


If you have backup, just use the backup file.
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
I have done that and it makes no difference - still fails. I don't see how the file is corrupted when I can read it in Notepad and there is no spot in the code that has "funny" characters. What kind of corruption do you suspect? But I will try one more time, just for luck. Thank you.

UPDATE: The trouble with that is I don't have a choice to open a new project that is NOT b4xPages. Yeah, I know that's the standard these days, but this project was done before b4xPages came along. And I don't feel like the hassle of dealing with all that after all the hassle I have already had. Maybe I will feel different after a night's sleep. This has sucked the life out of me today.

UPDATE: >> If you have backup, just use the backup file.

I have loads of backups and none of them work. I find the b4A editor and IDE unreliable. There are spooky times when the IDE changes code on me and makes various lines of code "jumbled". I have written about this before, but I can't reproduce the problem in any consistent way. All I know is that b4A can't be trusted, hence why I make tons of backups as I make code modifications.
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
I don't see how the file is corrupted when I can read it in Notepad
Corrupted means one of the keys may have been missing that is part of the project file format. The IDE unable to parse it correctly.
You still can read it using Notepad.

The keys includes Build1, File1, File2, ..., FileGroup1, FileGroup2, ..., Library1, Library2, ..., ManifestCode, Module1, Module2, ..., NumberOfFiles,
NumberOfLibraries, NumberOfModules.
Example, if this file has NumberOfFiles=3 but it only has File1 and File2 then File3 is missing. This is a "corrupted" file.
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
Corrupted means one of the keys may have been missing that is part of the project file format. The IDE unable to parse it correctly.
You still can read it using Notepad.

The keys includes Build1, File1, File2, ..., FileGroup1, FileGroup2, ..., Library1, Library2, ..., ManifestCode, Module1, Module2, ..., NumberOfFiles,
NumberOfLibraries, NumberOfModules.
Example, if this file has NumberOfFiles=3 but it only has File1 and File2 then File3 is missing. This is a "corrupted" file.
Thank you for that explanation. Seems like I could manually check that myself. Unless there are invisible keys as well. Yet if visible keys are missing, then copying the file to a new project would not solve anything.

I would think that the IDE should be smart enough to identify the specific problem instead of giving me a worthless, stupid error message that tells me nothing. Poor design, IMO.
 
Last edited:
Upvote 0

aeric

Expert
Licensed User
Longtime User
I am not sure this is due to memory leak in your OS or you are using AI to edit the file outside the IDE.
In case it happened, this is an easy fix.
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
I am not sure this is due to memory leak in your OS or you are using AI to edit the file outside the IDE.
In case it happened, this is an easy fix.
I don't use AI. But I do use TextPad to edit files at times, because the IDE is not 100% reliable. Also, TextPad is better at editing than the b4a IDE.
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I don't use AI. But I do use TextPad to edit files at times, because the IDE is not 100% reliable. Also, TextPad is better at editing than the b4a IDE.
I see.
Then make sure every time you add/remove any file, modules or libraries the number of files, modules and libraries keys are matching.
This is automatically updated if using the IDE.
 
Upvote 0

aedwall

Active Member
Licensed User
Longtime User
I see.
Then make sure every time you add/remove any file, modules or libraries the number of files, modules and libraries keys are matching.
This is automatically updated if using the IDE.
I do that. But thank you for the tip. Unless I'm blind, I don't see a problem with the below:

"Keys":
Build1=Default,a.edwall.natal.charts_500
File1=Layout.bal
File2=calendar.png
File3=clock.png
File4=help.txt
FileGroup1=Default Group
FileGroup2=Default Group
FileGroup3=Default Group
FileGroup4=Default Group
Group=Default Group
Library1=stringutils
Library2=betterdialogs
Library3=clipboard
Library4=core
Library5=dialogs
Library6=ime
Library7=json
Library8=okhttputils2
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="33"/>~\n~<supports-screens android:largeScreens="true" ~\n~    android:normalScreens="true" ~\n~    android:smallScreens="true" ~\n~    android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~'End of default text.~\n~SetApplicationAttribute(android:theme, "@style/LightTheme")~\n~CreateResource(values-v20, theme.xml,~\n~<resources>~\n~    <style~\n~        name="LightTheme" parent="@android:style/Theme.Material.Light">~\n~             <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>~\n~    </style>~\n~</resources>~\n~)~\n~CreateResource(values-v14, theme.xml,~\n~<resources>~\n~    <style~\n~        name="LightTheme" parent="@android:style/Theme.Holo.Light">~\n~                <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>~\n~    </style>~\n~</resources>~\n~)~\n~
NumberOfFiles=4
NumberOfLibraries=8
NumberOfModules=0
Version=13.4
@EndOfDesignText@

#Region Module Attributes
  #FullScreen: False
  #IncludeTitle: False
  #ApplicationLabel: Natal Charts v500
  #VersionCode: 1
  #VersionName: 500
  #SupportedOrientations: unspecified
  #CanInstallToExternalStorage: False
#End Region
 
Upvote 0

aeric

Expert
Licensed User
Longtime User
I do that. But thank you for the tip. Unless I'm blind, I don't see a problem with the below:

"Keys""Keys":
Build1=Default,a.edwall.natal.charts_500
File1=Layout.bal
File2=calendar.png
File3=clock.png
File4=help.txt
FileGroup1=Default Group
FileGroup2=Default Group
FileGroup3=Default Group
FileGroup4=Default Group
Group=Default Group
Library1=stringutils
Library2=betterdialogs
Library3=clipboard
Library4=core
Library5=dialogs
Library6=ime
Library7=json
Library8=okhttputils2
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="33"/>~\n~<supports-screens android:largeScreens="true" ~\n~    android:normalScreens="true" ~\n~    android:smallScreens="true" ~\n~    android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~'End of default text.~\n~SetApplicationAttribute(android:theme, "@style/LightTheme")~\n~CreateResource(values-v20, theme.xml,~\n~<resources>~\n~    <style~\n~        name="LightTheme" parent="@android:style/Theme.Material.Light">~\n~             <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>~\n~    </style>~\n~</resources>~\n~)~\n~CreateResource(values-v14, theme.xml,~\n~<resources>~\n~    <style~\n~        name="LightTheme" parent="@android:style/Theme.Holo.Light">~\n~                <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>~\n~    </style>~\n~</resources>~\n~)~\n~
NumberOfFiles=4
NumberOfLibraries=8
NumberOfModules=0
Version=13.4
@EndOfDesignText@

#Region Module Attributes
  #FullScreen: False
  #IncludeTitle: False
  #ApplicationLabel: Natal Charts v500
  #VersionCode: 1
  #VersionName: 500
  #SupportedOrientations: unspecified
  #CanInstallToExternalStorage: False
#End Region
I am able to open the project by pasting the code to a blank text file.
test.b4a:
Build1=Default,a.edwall.natal.charts_500
File1=Layout.bal
File2=calendar.png
File3=clock.png
File4=help.txt
FileGroup1=Default Group
FileGroup2=Default Group
FileGroup3=Default Group
FileGroup4=Default Group
Group=Default Group
Library1=stringutils
Library2=betterdialogs
Library3=clipboard
Library4=core
Library5=dialogs
Library6=ime
Library7=json
Library8=okhttputils2
ManifestCode='This code will be applied to the manifest file during compilation.~\n~'You do not need to modify it in most cases.~\n~'See this link for for more information: http://www.b4x.com/forum/showthread.php?p=78136~\n~AddManifestText(~\n~<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="33"/>~\n~<supports-screens android:largeScreens="true" ~\n~    android:normalScreens="true" ~\n~    android:smallScreens="true" ~\n~    android:anyDensity="true"/>)~\n~SetApplicationAttribute(android:icon, "@drawable/icon")~\n~SetApplicationAttribute(android:label, "$LABEL$")~\n~'End of default text.~\n~SetApplicationAttribute(android:theme, "@style/LightTheme")~\n~CreateResource(values-v20, theme.xml,~\n~<resources>~\n~    <style~\n~        name="LightTheme" parent="@android:style/Theme.Material.Light">~\n~             <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>~\n~    </style>~\n~</resources>~\n~)~\n~CreateResource(values-v14, theme.xml,~\n~<resources>~\n~    <style~\n~        name="LightTheme" parent="@android:style/Theme.Holo.Light">~\n~                <item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>~\n~    </style>~\n~</resources>~\n~)~\n~
NumberOfFiles=4
NumberOfLibraries=8
NumberOfModules=0
Version=13.4
@EndOfDesignText@

#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: False
    #ApplicationLabel: Natal Charts v500
    #VersionCode: 1
    #VersionName: 500
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

1780464384176.png
 
Upvote 0
Top