我正在使用volley
并且在几次点击之后抛出异常。
应用程序崩溃,显示以下错误。
E / StrictMode:在附加堆栈跟踪处获取资源但从未释放。有关避免资源泄漏的信息,请参阅java.io.Closeable。 java.lang.Throwable:未调用显式终止方法'close' 在dalvik.system.CloseGuard.open(CloseGuard.java:180) 在java.net.AbstractPlainSocketImpl.create(AbstractPlainSocketImpl.java:103) 在java.net.Socket.createImpl(Socket.java:464) 在java.net.Socket.getImpl(Socket.java:530) 在java.net.Socket.setSoSndTimeout(Socket.java:1194) 在com.android.okhttp.Connection.setTimeouts(Connection.java:508) 在com.android.okhttp.Connection.connectAndSetOwner(Connection.java:400) 在com.android.okhttp.OkHttpClient $ 1.connectAndSetOwner(OkHttpClient.java:130) 在com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:356) 在com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:273) 在com.android.okhttp.internal.huc.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:474) 在com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:422) 在com.android.okhttp.internal.huc.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:538) 在com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getResponseCode(DelegatingHttpsURLConnection.java:105) at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java) 在com.android.volley.toolbox.HurlStack.executeRequest(HurlStack.java:99) 在com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:131) 在com.android.volley.NetworkDispatcher.processRequest(NetworkDispatcher.java:120) 在com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:87)
以下是代码段
public void processServiceResponseEntity(final String serviceName, final String serviceRequest,
final int method, final String key, final Map<String, String> queryParams, final Map<String, String> header,
final Map<String, String> pathVariables)
throws YaggerCustomException
{
DatabaseHandler databaseHandler = new DatabaseHandler(context);
final User user = databaseHandler.getUserDetails();
String url = serviceName;
Log.d(TAG, "URL: " + url);
StringRequest strReq = new StringRequest(method,
url, new Response.Listener<String>() {
@Override
public void onResponse(String res) {
Log.d(TAG, "Response: " + res);
if (currentObject != null) {
currentObject.postYaggerServiceCall(res, key);
}
// setResponse(res);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Error: " + error.getMessage());
showSnackbar(serviceName, serviceRequest, method, key, queryParams, header, pathVariables);
currentObject.postYaggerServiceCall(null, key);
setError(error.getMessage());
// ACRA.getErrorReporter().handleException(new YaggerCustomException(error.getMessage()));
}
}) {
@Override
public String getBodyContentType()
{
if (getContentType() == null)
{
return "application/json";
}
else
{
return getContentType();
}
}
@Override
public byte[] getBody() throws AuthFailureError
{
byte[] byt = null;
this.getParams();
if (serviceRequest != null)
byt = serviceRequest.getBytes();
return byt;
}
@Override
public Map<String, String> getHeaders()
throws AuthFailureError
{
Map<String, String> oauthHeader = new HashMap<>();
oauthHeader.put("Content-Type", "application/json");
if(user != null)
oauthHeader.put("Authorization", user.getTokenType() + " " + user.getToken());
if (header != null && !header.isEmpty()) {
oauthHeader.putAll(header);
}
oauthHeader.putAll(super.getHeaders());
return oauthHeader;
}
@Override
public Map<String, String> getParams()
throws AuthFailureError
{
if (queryParams == null)
return Collections.<String, String>emptyMap();
return queryParams;
}
@Override
public RetryPolicy getRetryPolicy()
{
return new DefaultRetryPolicy(AppConfig.DEFAULT_TIMEOUT_MS, AppConfig.DEFAULT_MAX_RETRIES,
AppConfig.DEFAULT_BACKOFF_MULT);
}
};
// Adding request to request queue
strReq.setRetryPolicy(new DefaultRetryPolicy(AppConfig.DEFAULT_TIMEOUT_MS, AppConfig.DEFAULT_MAX_RETRIES,
AppConfig.DEFAULT_BACKOFF_MULT));
AppController.getInstance().addToRequestQueue(strReq, key == null ? serviceName : key);
}
由于