Hello,
Many thanks in advance for looking at this.
I’ve used the simple example code below from the Processing “thread()” reference:
String time = "";
void setup() {
size(100, 100);
}
void draw() {
background(0);
// Every 30 frames request new data
if (frameCount % 30 == 0) {
thread("requestData");
}
text(time, 10, 50);
}
// This happens as a separate thread and can take as long as it wants
void requestData() {
JSONObject json = loadJSONObject("http://time.jsontest.com/");
time = json.getString("time");
This works ok when running the sketch in Processing (Java), but when I switch to Android (running on a Samsung Galaxy S8) the app builds and loads ok but no time is displayed and its throwing these errors (repeatedly) to the processing console.
at java.io.BufferedReader.read(BufferedReader.java:193)
at processing.core.PApplet.createReader(PApplet.java:4715)
at processing.core.PApplet.createReader(PApplet.java:4666)
at processing.core.PApplet.loadJSONObject(PApplet.java:4133)
at processing.test.sketch_200421a.sketch_200421a.requestData(sketch_200421a.java:37)
at java.lang.reflect.Method.invoke(Native Method)
at processing.core.PApplet.method(PApplet.java:2862)
at processing.core.PApplet$4.run(PApplet.java:2892)
java.lang.RuntimeException: java.io.IOException: Stream closed
at processing.data.JSONTokener.next(JSONTokener.java:157)
at processing.data.JSONTokener.nextClean(JSONTokener.java:231)
at processing.data.JSONObject.(JSONObject.java:241)
at processing.data.JSONObject.(JSONObject.java:226)
at processing.core.PApplet.loadJSONObject(PApplet.java:4134)
at processing.test.sketch_200421a.sketch_200421a.requestData(sketch_200421a.java:37)
at java.lang.reflect.Method.invoke(Native Method)
at processing.core.PApplet.method(PApplet.java:2862)
at processing.core.PApplet$4.run(PApplet.java:2892)
Caused by: java.io.IOException: Stream closed
at java.io.BufferedInputStream.getInIfOpen(BufferedInputStream.java:161)
at java.io.BufferedInputStream.read1(BufferedInputStream.java:286)
at java.io.BufferedInputStream.read(BufferedInputStream.java:347)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:288)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:351)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:180)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:172)
at java.io.BufferedReader.read(BufferedReader.java:193)
at processing.data.JSONTokener.next(JSONTokener.java:155)
… 8 more
(HTTPLog)-Static: isSBSettingEnabled false
java.io.IOException: Cleartext HTTP traffic to time.jsontest.com not permitted
at com.android.okhttp.HttpHandler$CleartextURLFilter.checkURLPermitted(HttpHandler.java:115)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:467)
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:127)
at processing.core.PApplet.createInputRaw(PApplet.java:4855)
at processing.core.PApplet.createInput(PApplet.java:4809)
at processing.core.PApplet.createReader(PApplet.java:4661)
at processing.core.PApplet.loadJSONObject(PApplet.java:4133)
at processing.test.sketch_200421a.sketch_200421a.requestData(sketch_200421a.java:37)
at java.lang.reflect.Method.invoke(Native Method)
at processing.core.PApplet.method(PApplet.java:2862)
at processing.core.PApplet$4.run(PApplet.java:2892)
java.io.IOException: Stream closed
I have enabled all permissions on the Sketch itself and for the App when its running on Android, also I commented out the Thread call and the app just sat there no errors - so I’m pretty sure it’s something to do with that.
I suspect I am missing something like a library or there needs to be a different way to access HTTP thru’ android etc?
Processing Version 3.5.4
Win 10 64 Bit
SDK Android 9.0 (Pie) API 28
Samsung Galaxy S8 (device in which I run the sketch)
Any suggestions most appreciated.
Thanks,
Bob.