Solving Runtime errors

Then try this event:

grafik

I now have two independent error trapping event catchers.
I still have the problem that the Screen1 error handler does not catch my runtime error. The message given is exactly the same as before. Attempt to access item 1 of list of length zero:()
If you have any idea I would highly appreciate it.
Thanks again for your time.
Screenshot from 2022-07-02 15-16-30

The problem is you are attempting to read a List that does not yet contain any information; possibly because of a timing issue.

Check all your code where you attempt to read values from a List and you will discover the problem. :cry: You possibly can use DoIt to debug.

Use the MIT debugging advice Live Development, Testing and Debugging

and Enis's comments about the built-in DoIt debgger http://twodogapps.com/?page_id=686#DoIt

The error message indicates you have an issue. You do not want to trap the error. The message indicates it has been trapped. You want to FIX the error.

I have had a look at your blocks for the ChartSpinner. There do appear to be a couple of issues that might be causing the problem...

  1. You have 7 selections/items in the spinner (but you use item 1 as a header)
  2. in your after picking code:
  • you consider the selectionindex = 8, which is not possible (with only 7 items)?
  • you add 1 to the selection index which might take you over the 7 ?

Have a look at wherever you are selecting an item from a list in the afterpicking event and test it.

Spinners can display strange behaviour, this might help:

And what is the error with the parameter "funktionName"?

I looked at your .aia file.

Your BlueTooth message handling is based on immediate gratification, trying to pull in response data in the same events that request the data.

Most apps use only a Clock Timer for single message reads, and parse the incoming messages for data content.

They also don't make any assumptions as to what they will get when they split incoming messages. Tedious as it is, you have to check length of list before doing any select item from list.

By the Way, I notice you use CR as your message delimiter. Most people use NL (Decimal 10).

Evidence for the other Power Users:


BLueToothClient

Here is my standard boiler plate advice for BlueTooth Delimiters:

Please see the Delimiter article in FAQ

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
BlueToothClient1_Properties
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

TIMAI2, Thank you very much for your comment. My code was actually correct but extremely confusing because I use the dropdown selection to indicate a data column to be graphed. Very bad practice in my specific case. I spent the last half day separating the dropdown selection from that data column to graph. In the process I uncovered a can of worms due to legacy issues but unfortunately the runtime error is not solved. Let me follow up some of the other suggestions below. Thanks very much for your time.

@ABG: Thank you very much. These are extremely valuable comments. I appreciate your time.

@Anke,

Screenshot from 2022-07-03 14-41-10

This is my error mechanism. It is not triggered at all by the runtime error. Since the above error reporting block is not triggered by the runtime error, the function name remains unknown.

Im talking about the Bluetooth.Error event.

After sleeping on your data problem, I have some more thoughts for you ...

You are sending a wide variety of measurements, destined to be shown in lots of labels and destined to be graphed in various scales.

You currently request the data in a Command and Control fashion, tightly coupling your requests and responses.

If you switch to a JSON data stream (only 1 or 2 attributes per object to fit BlueTooth message size limitations, short key names to fit, decode using one of the Web component blocks into a dictionary or list of pairs), you can move to a table-driven setup where for each incoming tag/value you can look up:

  • which Label.Text shows the incoming reading?
  • what multiplicative (default=1) and additive factor (default=0) should be used to scale this reading (i.e. degF vs degC) ?
  • what suffix (default "") should be added to the reading in the display ("degF" , "degC", "
    Volts") ?
  • which Canvas should the incoming data be graphed on, and at what scale factors?
  • which file should the data be directed to, if at all?

This would eliminate some duplicate code and reduce your block count, and reduce blooper duplication. It also handles missing data more gracefully than counting list indices.

@ABG
You give me so many things to think about. I have never used JSON, I just know it is pretty text-intensive since it is JavaScript.
An approach really worthy of consideration. Give me time to sleep on this (!)
Thank you gain for your time and suggestion.

@Anke,
I see the BluetoothError event is deprecated and that one should use Screen.ErrorOccurred
I will need to carefully reconsider my code for error trapping.

Ok I didn't notice that.
The question remains why this event was not removed there?

I hope I understand you correctly. Why was the error not trapped? It is trapped by the Companion, as below:

Underneath is the blocks for the code as at present. This activates Notifier1 with information about indexing of the lists used.

The indexing works perfectly since the notifier shows:

Apologies for the large images above.
The runtime error is generated because of calling SetVerticalArrangement.Visible to true in the 2nd last statement of this block of code. There is no explicit indexing involved at all in this statement. My lists are therefore working exactly as expected and the problem lies in setting a VerticalArrangament to visible. I suspect I have either run into a bug in the AI2 or I am doing something irregular somewhere else. Are there any checks that I can do to better understand or resolve at all?

If I disable the SetVerticalArrangement block, then the code runs without any error.

Apologies for a fragmented text. If I select any other tab with index > 1, then there is no error. It is ONLY if ActiveTab = 1 that the error shows. The error arises from the VerticalArrangement passed to set.visible. Even if I insert ChartVerticalArrangement79 as the argument for set.visible, the runtime error is thrown. So indexing within this block of code is probably not involved, but the passing of the reference of the appropriate VerticalArrangement to set.visible throws the error.

Have a look at what is happening here: (in the red rectangles)

What does your TabScreens list look like ?
What is the value of activeTab ?

Screenshot from 2022-07-04 14-21-32

Tabscreens is a list of layouts as defined in the UI/Designer of AI2. See image above.

activeTab is an index (1-6) passed to the method from higher up in the code, determining which tab should be activated. The top part of the above method deactivates any active tab (if present; initially no tab is activated and previousTabNo=0). The middle part sets the appropriate colour and text for the new active tab. The bottom part of the code changes the attributes of the new active tab. Here are the tab layout in the Android UI with no tabs selected. The tabs are just buttons.

Here are the tabs after tab selection:

Something else:
If, in the VerticalArrangement.visible setting in your block above I insert a direct reference to the vertical arrangement (as used in the Initialize Global statement at the top) the error still occurs. If I insert a direct reference to any of the other tabs,(indices 2-6) NO error is thrown. E.g. if I select the second tab, NO error is thrown. I did an experiment by adding an extra element to TabScreens (i.e. list length=7) and do not use the 1st element but start using at the 2nd element (i.e. all tab references are moved one on in the list), then I still get an error when using the 1st (leftmost) tab (ChartVerticalTabArrangement79, now at index 2 in the list) and none of the other tabs raises an error. My conclusion is that there is something undefined in ChartVerticalTabArrangement79 (the layout of the leftmost tab). The reference is problematic irrespective of where in the list this reference to the leftmost tab is located. I hope my argument above is clear.

Oh, and I need to mention that the layouts actually refer to the screen layout in the area below the tabs. The layout does not refer to a button itself.