Android Question Type string array fails in MQTT subscribe

DickD

Active Member
Licensed User
I'm using MQTT. I created the type shown below that contains a string array. I load this array and publish it to MQTT successfully but when I subscribe to the message and try to use the serializator I get the error message shown below. Do I need convert the string to an object or vice versa?

error: java.lang.RuntimeException: java.lang.IllegalArgumentException: field dickddomain.com.Proximate.main$_profilestuff.Ques has type java.lang.String[][], got java.lang.Object[]

B4X:
 Type ProfileStuff(Desc As String, Picture() As Byte, Ques(31,36) As String)
 Dim ProfileIn as ProfileStuff
.....
ProfileIn.initialize
....
Private Sub mqtt_MessageArrived (Topic As String, Payload() As Byte)
Dim obj as object
 obj = serializator.ConvertBytesToObject(Payload)
' error occurs here
 

rboeck

Well-Known Member
Licensed User
Longtime User
Hi, i use exactly the same last line, which produces the error, for more than two years - so i believe, the problem is, how you send the object.
We cant see, how you do this; maybe you should transfer your string array to an object (if possible) and send this object. Than the receive of an object should work too.
 
Upvote 0

DickD

Active Member
Licensed User
Hi, i use exactly the same last line, which produces the error, for more than two years - so i believe, the problem is, how you send the object.
We cant see, how you do this; maybe you should transfer your string array to an object (if possible) and send this object. Than the receive of an object should work too.
I've tried converting to an object. I get this error: java.lang.RuntimeException: java.lang.IllegalArgumentException: field dickddomain.com.Proximate.main$_profilestuff.Ques has type java.lang.Object[][], got java.lang.Object[].

Notice the difference in the number of brackets (dimensions) sent [][] vs. got []. After a lot of experimenting I think I understand now that Types are limited to a 1 dimensional array.

I'd like to know if anyone has gotten Types to work with multidimensional arrays.
 
Upvote 0

rboeck

Well-Known Member
Licensed User
Longtime User
I think you want to transfer always one element of an two dimensional array; why you dont declare one variable only for this transfer as helper?
 
Upvote 0

DickD

Active Member
Licensed User
I think you want to transfer always one element of an two dimensional array; why you dont declare one variable only for this transfer as helper?
Yes. I made the 2D array into 1 simply be reducing one dimension to a string with separators. It works as a 1D array.
 
Upvote 0

DickD

Active Member
Licensed User
I think you want to transfer always one element of an two dimensional array; why you dont declare one variable only for this transfer as helper?
I spoke too soon. This still is not working. After a lot of research I finally discovered that arrays are not allowed in type variables. You can have arrays OF type variables not arrays IN type variables. It's as simple as that. I just wish that had been stated clearly in the documentation on this subject.
 
Upvote 0
Top