I just noticed that my released app is occasionally crashing for people with a null pointer error on one line of code.
The error would seem to indicate that "BT_MacAdr" has somehow become a null pointer. Looking at my code I see there is one place where I initialize "BT_MacAdr" with a previously saved value with this line of code:
My question is can the ReadLine fail in such a way that "BT_MacAdr" is set to a Null pointer value.
For example the file ends while trying to read that line or has data that can not be converted to a string. There is a Try Catch around the ReadLine code so any failure there would not crash the app.
I would expect that if there was any problem with the tr.ReadLine it would just set "BT_MacAdr" to an empty string not to a null pointer value which could cause a crash later in the app.
Actually, I don't understand how a string variable can ever be a null pointer. By default it should always be a null string (empty string) until assigned a value and so should never cause a null pointer crash of an app.
Here an example of the error message:
B4X:
Dim BT_MacAdr As String = "00:00:00:00:00:00"
...
Using_WiFi=Not((BT_MacAdr="") Or BT_MacAdr.contains(":") Or (BT_MacAdr="BTLE"))
The error would seem to indicate that "BT_MacAdr" has somehow become a null pointer. Looking at my code I see there is one place where I initialize "BT_MacAdr" with a previously saved value with this line of code:
B4X:
BT_MacAdr = tr.ReadLine
My question is can the ReadLine fail in such a way that "BT_MacAdr" is set to a Null pointer value.
For example the file ends while trying to read that line or has data that can not be converted to a string. There is a Try Catch around the ReadLine code so any failure there would not crash the app.
I would expect that if there was any problem with the tr.ReadLine it would just set "BT_MacAdr" to an empty string not to a null pointer value which could cause a crash later in the app.
Actually, I don't understand how a string variable can ever be a null pointer. By default it should always be a null string (empty string) until assigned a value and so should never cause a null pointer crash of an app.
Here an example of the error message:
B4X:
java.lang.NullPointerException: Attempt to invoke virtual method 'boolean java.lang.String.equals(java.lang.Object)' on a null object reference
Last edited: