Hashtable Point of Interest

 

 

 

 

While working on the development of a relatively simple navigation/tab control I have come accross the following issue:

Navigation control contains buttons on the navigation bar, and by clicking on them the appropriate panel appears.
 

I wanted to save which panel appears by clicking a certain button in hashtable.
 

The button was supposed to be the hashtable’s key, while the panel its value.
 

Although my solution worked perfectly in the MobiAccess emulator, on Android phones a "java.lang.NullPointerException - null" error message appeared when I tried to add the button-panel pair to the hashtable: hashtable.Add(button, panel);


Test:

 

I wrote a little test that I used to examine which keys cause the error:

var ex:Exception;

try

{

    var hashTable:HashTable = HashTable.CI();
 

    //it is working

    //hashTable.Add("stringkey", Panel.CI());

    //hashTable.Add(12, Panel.CI());

    //hashTable.Add(MainForm.CI(), Panel.CI());
 

    //exception occured on android

    //hashTable.Add(Button.CI(), Panel.CI());

    //hashTable.Add(Label.CI(), Panel.CI());

    hashTable.Add(TextBox.CI(), Panel.CI());

 

    MessageBox.Show("SUCCESSFUL", "Item Added", EMessageBoxButtons.OK); }

catch(ex)

{

    MessageBox.Show("ERROR", ex.GetMessage(), EMessageBoxButtons.OK); }

It is intriguing that although the mainform does not cause an issue, all the other standard controls (button, label, textbox) do.



Workaround:
 

I created a class (NavigationItem), which contains a Button and a Panel variable.
 

I stored these navigation items in a List type object. Implicitly an add and a get method was required for this, meaning that I practically mimicked the functioning of the hashtable.
 

According to the MobiAccess developer team the issue has been solved, and it will not reemerge from the next release.



Written by PK

Add comment


Security code
Refresh