简体   繁体   中英

“Buffer Error”, "Error converting result java.lang.NullPointerException: lock == null

Here is my java code where I am getting this error in google map

public String getJSONFromUrl(String url)
{ 

    try {
        Log.e("jsonURL", url);
        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();

        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }

        json = sb.toString();
        is.close();
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }
    return json;
}

I am calling this method here

    protected String doInBackground(Void... params) {      
        JSONParser jParser = new JSONParser();
        String json = jParser.getJSONFromUrl(url);
        return json;
    }

Please suggest me the way to resolve this issue.

here is the url: https://maps.googleapis.com/maps/api/directions/json?origin=30.7019818,76.6836021&destination=31.344452033528295,48.71375273913145&sensor=false&mode=driving&alternatives=true&key= google_api_key

Here is the logcat

10-06 18:54:18.529 17583-18349/com.app.io.taxiapp W/System.err: Caused by: android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused) 10-06 18:54:18.529 17583-18349/com.app.io.taxiapp W/System.err: at libcore.io.Posix.connect(Native Method) 10-06 18:54:18.529 17583-18349/com.app.io.taxiapp W/System.err: at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111) 10-06 18:54:18.529 17583-18349/com.app.io.taxiapp W/System.err: at libcore.io.IoBridge.connectErrno(IoBridge.java:137) 10-06 18:54:18.529 17583-18349/com.app.io.taxiapp W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:122) 10-06 18:54:18.529 17583-18349/com.app.io.taxiapp W/System.err: ... 21 more 10-06 18:54:18.539 17583-17708/com.app.io.taxiapp D/libEGL: eglInitialize EGLDisplay = 0xeeafa60c 10-06 18:54:18.539 17583-17708/com.app.io.taxiapp D/libEGL: eglTerminate EGLDisplay = 0xeeafa66c 10-06 18:54:18.549 17583-17583/com.app.io.taxiapp I/Timeline: Timeline: Activity_idle id: android.os.BinderProx y@7f3946f time:11454827 10-06 18:54:18.559 17583-18349/com.app.io.taxiapp E/Buffer Error: Error converting result java.io.IOException: Attempted read on closed stream.

I've resolved the issue. Actually data compression mode was on in my device which was stopping many apps to consume internet connectivity, google play services was also one of them. That's why I was getting this error connect failed: ECONNREFUSED (Connection refused)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM