Hi,
in the following code I am defining a byte array - afterwards I want to check if it has been set or not by checking if it is null ...
Dim data() As Byte
....
If data = Null Then ExitApplication
When I try to compile I get the following:
Compiling generated Java code. Error
B4A line: 92
If data = Null Then ExitApplication
javac 1.6.0_24
src\hawkstone\epod\actprocessdoc.java:323: incomparable types: byte[] and double
if (_data==(double)(BA.ObjectToNumber(anywheresoftware.b4a.keywords.Common.Null))) {
^
Obviously I cannot check the length as the variable value is actually null. Is there another / better way of checking if arrays has been assigned values ???
Actually you can. Basic4android will never leave a variable uninitialised so it is quite safe to check the length. In your case it will return zero as Dim a() and Dim a(0) are the same.
I am getting it from the camera - if the user decides not to use the image, the data variable is null ...
One thing, the data array is part of a type defined in a code module, might this maybe have an effect at all (type abc (data() as byte, ...) ???
It seems we both are correct ;-)
Local variables are assigned, global variables that is a "type" variable does not seem to be initialized ... maybe I am using it wrong, will have to experiment a bit and see ...
I misunderstood what you meant by set, I assumed ReDimmed. You can use a Reflector Object as a workaround.
B4X:
Dim ba() As Byte
...
Dim Obj1 As Reflector
Obj1.Target = ba
If Obj1.Target = Null Then ' or If Obj1.IsNull Then
ToastMessageShow("Null",True)
Else
ToastMessageShow(Obj1.Target,True)
End If
Once you assign the value from the camera then the previous value is discarded. So if the camera returns null then you will get a null array.
Your checking code is correct. It seems like a bug in the compiler.
The workaround is to explicitly convert the array to an object:
B4X:
Dim o As Object
o = Data
If o = Null then ...
'continue working with Data