I would like to know how to consume a REST service using totalcross.
I made an example following what is in the documentation, I am using HttpStream.
String url = enderecoWS + servico;
HttpStream hs = new HttpStream(new URI(url));
byte[] buf = new byte[hs.contentLength];
hs.readBytes(buf, 0, hs.contentLength);
String str = new String(buf);
But in the byte[] buf = new byte[hs.contentLength]
line, the value of contentLength
is -1 and generates
Exception: class java.lang.NegativeArraySizeException.
I made a change in the above code by changing hs.contentLength
to hs.readLine().length()
, this way I get the return, but a part of the string.
Another thing, if I have the following situation:
- Group Class
- Subgroup class
Where the Subgroup class has an object of type group. When using JSONFactory
this way:
Subgrupo[] subgrupoArray = JSONFactory.parse(str, Subgrupo[].class);
It gives error:
java.lang.IllegalAccessException: Can not call newInstance() on the Class for java.lang.Class