【问题标题】:"Buffer Error", "Error converting result java.lang.NullPointerException: lock == null"缓冲区错误", "错误转换结果 java.lang.NullPointerException: lock == null
【发布时间】:2018-03-18 05:20:08
【问题描述】:

这是我在谷歌地图中遇到此错误的 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;
}

我这里调用这个方法

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

请建议我解决此问题的方法。

这是网址: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

这里是日志

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 更多 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.BinderProxy@7f3946f time:11454827 10-06 18:54:18.559 17583-18349/com.app.io.taxiapp E/Buffer 错误:转换结果时出错 java.io.IOException:尝试在关闭的流上读取。

【问题讨论】:

  • 你能把这个:Log.e("Buffer Error", "Error converting result " + e.toString()); 替换成 Log.e("Buffer Error", "Error converting result ", e); 并从 logcat 发布整个堆栈跟踪吗?
  • 请检查我已编辑问题。
  • Caused by: android.system.ErrnoException: connect failed: ECONNREFUSED (Connection refused) 我认为这是您问题的根源。您的连接被拒绝,因此您的 InputStream is 为空/null,因为 is = httpEntity.getContent(); 失败。
  • 相同的代码在其他设备上运行良好,但在我的设备 android M 中应用程序崩溃了。

标签: java android google-maps


【解决方案1】:

我已经解决了这个问题。实际上,我的设备中的数据压缩模式已打开,这会阻止许多应用程序使用互联网连接,谷歌播放服务也是其中之一。这就是为什么我收到此错误连接失败:ECONNREFUSED(连接被拒绝)

【讨论】:

    猜你喜欢
    • 2015-04-12
    • 1970-01-01
    • 2015-08-27
    • 2016-07-10
    • 1970-01-01
    • 2014-06-23
    • 2013-11-07
    • 1970-01-01
    • 2016-07-17
    相关资源
    最近更新 更多