简体   繁体   English

“缓冲区错误”,“转换结果java.lang.NullPointerException时出错:lock == null

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

Here is my java code where I am getting this error in google map 这是我的Java代码,我在谷歌地图中收到此错误

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 这是网址: 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 这是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 10-06 18:54:18.529 17583-18349 / com.app.io.taxiapp W / System.err:原因:android.system.ErrnoException:连接失败:ECONNREFUSED(连接被拒绝)10-06 18:54:18.529 17583-18349 / com.app.io.taxiapp W / System.err:位于libcore.io.Posix.connect(本机方法)10-06 18:54:18.529 17583-18349 / com.app.io.taxiapp W / System.err:位于libcore.io.BlockGuardOs.connect(BlockGuardOs.java:111)10-06 18:54:18.529 17583-18349 / com.app.io.taxiapp W / System.err:位于libcore.io.IoBridge .connectErrno(IoBridge.java:137)10-06 18:54:18.529 17583-18349 / com.app.io.taxiapp W / System.err:位于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 /时间轴:时间轴: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. y @ 7f3946f时间:11454827 10-06 18:54:18.559 17583-18349 / com.app.io.taxiapp E / Buffer错误:转换结果java.io.IOException时出错:尝试在关闭的流上读取。

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. 实际上,我的设备上启用了数据压缩模式,该模式正在阻止许多应用程序消耗互联网连接,而Google Play服务也是其中之一。 That's why I was getting this error connect failed: ECONNREFUSED (Connection refused) 这就是为什么我收到此错误连接失败的原因:ECONNREFUSED(连接被拒绝)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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