Code:
compiles with Error for the last line _command = ...
Cannot find symbol ':getCharacteristic' on type 'Null'.
I can't find spot my mistake. Any hints?
Code:
compiles with Error for the last line _command = ...
Cannot find symbol ':getCharacteristic' on type 'Null'.
I can't find spot my mistake. Any hints?
TL;DR it's a compiler bug.
I modified your code as follows so I could reproduce your problem without _profileManager.
class DeviceManager {
private var _device as Device?;
private var _service as Service?;
private var _command as Characteristic?;
private var _config as Characteristic?;
private function startFlControl() as Void {
var device = _device;
if (null != device) {
// _service = device.getService(_profileManager.FL_SERVICE);
_service = device.getService(BluetoothLowEnergy.stringToUuid("fakeuuid"));
if (null != _service) {
_config = _service.getCharacteristic(BluetoothLowEnergy.stringToUuid("fakeuuid"));
_command = _service.getCharacteristic(BluetoothLowEnergy.stringToUuid("fakeuuid"));
}
}
}
}
I got the same compilation error on _command = ...
Seems to be yet another compiler bug. In this case, it seems that the compiler knowledge's that _service != null is only applied to the first line of the if block (_config = ...).
I was able to work around this in a few different ways.
1) This is the worst one lol:
if (null != _service) {
_config = _service.getCharacteristic(BluetoothLowEnergy.stringToUuid("fakeuuid"));
}
if (null != _service) {
_command = _service.getCharacteristic(BluetoothLowEnergy.stringToUuid("fakeuuid"));
}
2) A bit better:
if (null != _service) {
var service = _service;
_config = service.getCharacteristic(BluetoothLowEnergy.stringToUuid("fakeuuid"));
_command = service.getCharacteristic(BluetoothLowEnergy.stringToUuid("fakeuuid"));
}
3) This is probably the best way in terms of memory efficiency, as it won't waste memory in additional code at runtime:
(It does leave you open to accidentally casting to the wrong type and causing a run-time error)
if (null != _service) {
_config = (_service as Service).getCharacteristic(BluetoothLowEnergy.stringToUuid("fakeuuid"));
_command = (_service as Service).getCharacteristic(BluetoothLowEnergy.stringToUuid("fakeuuid"));
}
I'd say 2) is actually the best approach if you're worried about type-safety. 3) is the best if you care less about type safety and more about saving memory.
Thanks. Indeed i already found 2) in the NordicThingy52 example provided by Garmin in the SDK, but i did not understand it. Did not think of a compiler error workaround...
I am using Garmin CIQ for around 4 weeks now. In this time i ran in two times in problem, that was confirmed as compiler errors. Looks like the CIQ platform is still in a beta state?
The compile-time type checking stuff doesn't seem ready for prime time, for sure.
As for the rest of the platform, I guess you can browse this forum and look at the bug reports section, and judge for yourself.
I feel like there's enough problems even without CIQ (take a look at the 255 and 955 forums).
Indeed i already found 2) in the NordicThingy52 example provided by Garmin in the SDK, but i did not understand it.
Yeah, long story short and as you've already seen, the type checking behavior for local variables is slightly different than the behavior for member variables or global variables.