Check if byte array variable set

francoisg

Active Member
Licensed User
Longtime User
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 ???
 
mmm.. then I am doing something wrong - "Log(Data.Length)" gives a null pointer exception ...
 
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.

Code:
   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
 
variables that is a "type" variable does not seem to be initialized
It was initialised but you assigned null to it and lost the original zero length array.

EDIT:- Assuming that you did call Initialize on it like you should with all "type" variables.
 
Last edited:
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:
Code:
Dim o As Object
o = Data
If o = Null then ...
'continue working with Data
 
Back
Top