Android开发Android开发Android技术知识

Cannot access request header fie

2018-06-22  本文已影响34人  chenxuxu

今天测试时,发现有个地方没修改过代码,但是却出现一个奔溃问题。

java.lang.IllegalStateException: Cannot access request header fields after connection is set
    at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getRequestProperties(HttpURLConnectionImpl.java:231)
    at com.android.tools.profiler.support.network.httpurl.TrackedHttpURLConnection.getRequestProperties(TrackedHttpURLConnection.java:204)
    at com.android.tools.profiler.support.network.httpurl.TrackedHttpURLConnection.trackPreConnect(TrackedHttpURLConnection.java:63)
    at com.android.tools.profiler.support.network.httpurl.TrackedHttpURLConnection.getInputStream(TrackedHttpURLConnection.java:354)
    at com.android.tools.profiler.support.network.httpurl.HttpURLConnection$.getInputStream(HttpURLConnection$.java:207)

通过多次尝试,发现网上有个方法可以解决:
inputStream = connection.getInputStream();放到int fileLength = connection.getContentLength();前面即可。
之前一直没问题,但是升级了buildToolsVersioncompileSdkVersion版本就出现此问题了。

上一篇下一篇

猜你喜欢

热点阅读