java.lang.IllegalStateException

There are no available Samebug tips for this exception. Do you have an idea how to solve this issue? A short tip would help users who saw this issue last week.

  • When an instance of TiHTTPClient is reused for another request with a file passed in the data the contentLength is not calculated properly. The request passes but the "onLoad" event is not dispatched. *Test case*: Click "Get Photos", wait for the reponse, dismiss the alert, and then click "Upload photo" - the request finishes but the "onload" event listener is not called. {code:javascript} var window = Ti.UI.createWindow(); var buttonUpload = Ti.UI.createButton({title:"Upload", top:50}); var buttonGetPhotos = Ti.UI.createButton({title:"Get Photos", top: 110}); var xhr = Titanium.Network.createHTTPClient({timeout:5000}); var tempF = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory,"simpleTest.png"); Ti.API.info(tempF); buttonUpload.addEventListener('click', function (e) { xhr.open("POST","https://requestb.in/zwfzmzzw"); var data_to_send = { "file": tempF.read(), }; xhr.onload = function () {(alert(this.responseText))}; xhr.send(data_to_send); }); buttonGetPhotos.addEventListener('click', function (e) { xhr.open("POST","https://requestb.in/zwfzmzzw"); var params = { id:46 }; xhr.onload = function (e) {alert(this.responseText)}; xhr.send(params); }); window.add(buttonGetPhotos); window.add(buttonUpload); window.open(); {code} _Another instance of requestb.in may need to be created for testing._ *Console Log:* {code:console} E/TiHTTPClient: (TiHttpClient-2) [142,13649] HTTP Error (java.lang.IllegalStateException): state: 2 java.lang.IllegalStateException: state: 2 at com.android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:186) at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:80) at com.android.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:906) at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:782) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:463) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:405) at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:521) at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105) at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java) at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1231) at java.lang.Thread.run(Thread.java:761) {code}
    via by gianluca,
    • java.lang.IllegalStateException: Not on the main thread 11-05 10:48:56.504: W/System.err(5498): at com.google.j.a.cl.b(Unknown Source) 11-05 10:48:56.504: W/System.err(5498): at com.google.maps.api.android.lib6.c.br.b(Unknown Source) 11-05 10:48:56.504: W/System.err(5498): at com.google.maps.api.android.lib6.c.dw.a(Unknown Source) 11-05 10:48:56.504: W/System.err(5498): at com.google.android.gms.maps.internal.l.onTransact(SourceFile:51) 11-05 10:48:56.505: W/System.err(5498): at android.os.Binder.transact(Binder.java:380) 11-05 10:48:56.505: W/System.err(5498): at com.google.android.gms.maps.internal.IGoogleMapDelegate$a$a.getCameraPosition(Unknown Source) 11-05 10:48:56.505: W/System.err(5498): at com.google.android.gms.maps.GoogleMap.getCameraPosition(Unknown Source) 11-05 10:48:56.505: W/System.err(5498): at com.reddatura.freecharging_beta.MapView$GetNewPins.doInBackground(MapView.java:241) 11-05 10:48:56.505: W/System.err(5498): at com.reddatura.freecharging_beta.MapView$GetNewPins.doInBackground(MapView.java:1) 11-05 10:48:56.505: W/System.err(5498): at android.os.AsyncTask$2.call(AsyncTask.java:288) 11-05 10:48:56.505: W/System.err(5498): at java.util.concurrent.FutureTask.run(FutureTask.java:237) 11-05 10:48:56.505: W/System.err(5498): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231) 11-05 10:48:56.505: W/System.err(5498): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 11-05 10:48:56.505: W/System.err(5498): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 11-05 10:48:56.505: W/System.err(5498): at java.lang.Thread.run(Thread.java:818) thanks Peter for that. SO the problem doesn't seem to be at onPostExecute as I initially thought, but it is the doinbackground, where I want to get the campos variable EDIT3: as Adogeon advised I've put the whole thing in the main loop, but there is this exception, which I was aware, just for the sake why I used asynctask for this...but I am prone to other suggestions 11-05 11:28:06.926: W/System.err(6417): android.os.NetworkOnMainThreadException 11-05 11:28:06.927: W/System.err(6417): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1147) 11-05 11:28:06.927: W/System.err(6417): at libcore.io.BlockGuardOs.recvfrom(BlockGuardOs.java:249) 11-05 11:28:06.927: W/System.err(6417): at libcore.io.IoBridge.recvfrom(IoBridge.java:553) 11-05 11:28:06.927: W/System.err(6417): at java.net.PlainSocketImpl.read(PlainSocketImpl.java:485) 11-05 11:28:06.927: W/System.err(6417): at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:37) 11-05 11:28:06.927: W/System.err(6417): at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:237) 11-05 11:28:06.927: W/System.err(6417): at com.android.okio.Okio$2.read(Okio.java:113) 11-05 11:28:06.927: W/System.err(6417): at com.android.okio.RealBufferedSource.indexOf(RealBufferedSource.java:147) 11-05 11:28:06.927: W/System.err(6417): at com.android.okio.RealBufferedSource.readUtf8LineStrict(RealBufferedSource.java:94) at com.android.okhttp.internal.http.HttpConnection.readResponse(HttpConnection.java:175) at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:101) at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:616) at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:379) at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:323) at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:190) at com.reddatura.serverside.FreechargingAPI.ExecuteGET(FreechargingAPI.java:42) at com.reddatura.serverside.FreechargingAPI.GetUnitsOnMap(FreechargingAPI.java:100) at com.reddatura.freecharging_beta.MapView$1.onMapSettled(MapView.java:101) at com.reddatura.listeners.MapStateListener.settleMap(MapStateListener.java:119) at com.reddatura.listeners.MapStateListener$4$1.run(MapStateListener.java:78) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5221) at java.lang.reflect.Method.invoke(Native Method)

    Users with the same issue

    Unknown visitor1 times, last one,
    ben.slama.jihed
    8 times, last one,