I'm doing an app that has several calls get using Volley (both string and JSON) and unpredictably (I can not tell when it's going to jump) I skip the following error:
java.lang.NegativeArraySizeException: -603
at com.android.volley.toolbox.DiskBasedCache.streamToBytes(DiskBasedCache.java:323)
at com.android.volley.toolbox.DiskBasedCache.get(DiskBasedCache.java:119)
at com.android.volley.CacheDispatcher.run(CacheDispatcher.java:100)
I also give an example of one of my calls:
protected void ponerFondo(final RelativeLayout abl) {
//la razón de que aquí haya un handler es para pedir dos veces la misma consulta, ya que a veces no coge bien el string a la primera
recargar.postDelayed(new Runnable() {
@Override
public void run() {
recargar.removeCallbacksAndMessages(null);
ponerFondo(abl);
}
}, 800);
requestQueue = Volley.newRequestQueue(getApplicationContext());
String StringURL = "url";
StringRequest stringRequest = new StringRequest(Request.Method.GET, StringURL,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
btn12 = (ImageButton) findViewById(R.id.btn12);
String imagenes[];
imagenes = response.split("#");
Picasso.with(getApplicationContext()).load(imagenes[0]).placeholder(abl.getBackground()).into(new Target(){
@Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
abl.setBackground(new BitmapDrawable(bitmap));
}
@Override
public void onBitmapFailed(final Drawable errorDrawable) {
ponerFondo(abl);
}
@Override
public void onPrepareLoad(final Drawable placeHolderDrawable) {
// Log.d("TAG", "Prepare Load");
}
});
if(!imagenes[1].equals("null")) {
Picasso.with(getApplicationContext()).load(imagenes[1]).into(btn12);
btn12.setVisibility(View.VISIBLE);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
ponerFondo(abl);
}
});
requestQueue.add(stringRequest);
}