Titanium JIRA Archive
Appcelerator Community (AC)

[AC-3721] TiHTTPClient java.lang.NullPointerException

GitHub Issuen/a
TypeBug
Priorityn/a
StatusClosed
ResolutionInvalid
Resolution Date2016-06-12T05:02:33.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterAndrea
AssigneeShak Hossain
Created2016-06-02T20:16:06.000+0000
Updated2016-06-13T02:07:13.000+0000

Description

I'm using method Ti.Network.createHTTPClient in order to call a php service passing post variables. I get a java.lang.NullPointerException

Comments

  1. Andrea 2016-06-02

    [ERROR] : TiHTTPClient: (TiHttpClient-2) [732,732] HTTP Error (java.lang.NullPointerException): java.lang.NullPointerException [ERROR] : TiHTTPClient: java.lang.NullPointerException [ERROR] : TiHTTPClient: at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:783) [ERROR] : TiHTTPClient: at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:347) [ERROR] : TiHTTPClient: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296) [ERROR] : TiHTTPClient: at com.android.okhttp.internal.http.HttpURLConnectionImpl.getHeaderField(HttpURLConnectionImpl.java:143) [ERROR] : TiHTTPClient: at java.net.URLConnection.getHeaderFieldInt(URLConnection.java:544) [ERROR] : TiHTTPClient: at java.net.URLConnection.getContentLength(URLConnection.java:316) [ERROR] : TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient.handleResponse(TiHTTPClient.java:159) [ERROR] : TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient.access$1200(TiHTTPClient.java:85) [ERROR] : TiHTTPClient: at ti.modules.titanium.network.TiHTTPClient$ClientRunnable.run(TiHTTPClient.java:1207) [ERROR] : TiHTTPClient: at java.lang.Thread.run(Thread.java:841)
  2. Andrea 2016-06-02

    var client = Ti.Network.createHTTPClient({ // function called when the response data is available onload : function(e) { Ti.API.info("Received text: " + this.responseText); alert('success'); }, // function called when an error occurs, including a timeout onerror : function(e) { Ti.API.debug(e.error); alert('error'); }, timeout : 5000 // in milliseconds }); // Prepare the connection. //client.open("POST", url); client.open("POST", url); client.send({ "type" : "getcategories", "sourcetype" : "source_app", });
  3. Andrea 2016-06-02

    Of course if I call the php file from my browser I get the http response without any problem
  4. Ashraf Abu 2016-06-06

    Testing this with:
       var url = "http://mockbin.com/request?foo=bar&foo=baz";
       var client = Ti.Network.createHTTPClient({
           // function called when the response data is available
           onload: function(e) {
               Ti.API.info("Received text: " + this.responseText);
               alert('success');
           },
           // function called when an error occurs, including a timeout
           onerror: function(e) {
               Ti.API.debug(e.error);
               alert('error');
           },
           timeout: 5000 // in milliseconds
       });
       // Prepare the connection.
       //client.open("POST", url);
       client.open("POST", url);
       //Set headers here.
       //client.setRequestHeader('Content-Type','text/csv');
       client.send({
           "type": "getcategories",
           "sourcetype": "source_app",
       });
       
    I do not find any issues. Could it be that your server expects something in the headers which causes it to give a wrong response?
  5. Sharif AbuDarda 2016-06-09

    Hello, I can reconfirm that the issue is not occurring with Ashraf Abu's code. Can you follow his guide, or provide more info? Regards, Sharif.
  6. Andrea 2016-06-11

    I re-installed Titanium sdk, and everything is ok now, tsk
  7. Ashraf Abu 2016-06-13

    That's good to hear. Let us know if this reproduces again some how.

JSON Source