Hola amigos tengo una duda. Tengo un menu Drawer en el cual utilizo diversos fragments para consultar un servicio de internet que esta consumida con volley pero al cambiar de fragment sin que alla terminado de cargar esa vista se colapsa la aplicacion.
anexo codigo
Codigo de llama a los fragments desde el menu drawer
if (id == R.id.nav_resumen) {
fm.beginTransaction().replace(R.id.frame, new ResumenFragment()).commit();
setTitle("Resumen");
} else if (id == R.id.nav_perfil) {
fm.beginTransaction().replace(R.id.frame, new ProfileFragment()).commit();
setTitle("Perfil");
} else if (id == R.id.nav_asignadas) {
//startActivity(new Intent(this, TerminarEnvioActivity.class));
fm.beginTransaction().replace(R.id.frame, new AsignadasFragment()).commit();
setTitle("Asignadas");
// Toast.makeText(context, "Free", Toast.LENGTH_SHORT).show();
} else if (id == R.id.nav_historial) {
fm.beginTransaction().replace(R.id.frame, new HistorialFragment()).commit();
setTitle("Historial");
Codigo que uso en cada fragment para llamar a mi servicio con Volley
private void cargarDatos()
{
progressBar.setVisibility(View.VISIBLE);
String urlBASE="https://" + UrlRemote.baseDebug + UrlRemote.EndPointProfile;
ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("driver_id",driver_id));
params.add(new BasicNameValuePair("number", driver_id));
NameValuePair Dato = SecurityUtils.getSignature(urlBASE, params);
try {
url2 = new URL(urlBASE + UrlRemote.getQuery(params));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String Firma = String.valueOf(Dato);
String URLFINAL = url2+"&"+Firma;
jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, URLFINAL, null,this,this);
jsonObjectRequest.setRetryPolicy(myRetryPolicy());
VolleySingleton.getInstance(thiscontext).addToRequestQueue(jsonObjectRequest);
}
@Override
public void onErrorResponse(VolleyError error) {
progressBar.setVisibility(View.INVISIBLE);
Toast.makeText(getActivity(), "No se puede optener los datos "+ error , Toast.LENGTH_SHORT).show();
Log.i("error", error.toString());
}
@Override
public void onResponse(JSONObject response) {
progressBar.setVisibility(View.INVISIBLE);
Profile profile = new Profile();
JSONObject jsonObject = null;
jsonObject = response.optJSONObject("Driver");
profile.setBonus(jsonObject.optString("bonus"));
profile.setCommissions(jsonObject.optString("commissions"));
profile.setMonth(jsonObject.optString("month"));
profile.setDriver_name(jsonObject.optString("Driver_name"));
profile.setTotal(jsonObject.optString("total"));
profile.setCycle(jsonObject.optString("cycle"));
profile.setDriver_user(jsonObject.optString("Driver_user"));
profile.setDriver_telephone(jsonObject.optString("Driver_telephone"));
profile.setDriver_photo_url(jsonObject.optString("Driver_photo_url"));
profile.setDiscounts(jsonObject.optString("discounts"));
profile.setDriver_ranking(jsonObject.optString("Driver_ranking"));
profile.setDairy(jsonObject.optString("dairy"));
profile.setBalance(jsonObject.optString("balance"));
profile.setDriver_plate(jsonObject.optString("Driver_plate"));
profile.setPending(jsonObject.optString("pending"));
//Vaciar los datos en los elementos
Glide.with(getActivity())
.load(profile.getDriver_photo_url())
.into(circleImageView);
nameDriver.setText(profile.getDriver_name().toString());
userDriver.setText(profile.getDriver_user().toString());
telefonoDriver.setText(profile.getDriver_telephone().toString());
plateDriver.setText(profile.getDriver_plate().toString());
ratingBar.setRating(Float.parseFloat(profile.getDriver_ranking()));
//Vacias datos de sueldos del perfil
textSueldo.setText(profile.getBalance().toString());
textComisiones.setText(profile.getCommissions().toString());
textBonos.setText(profile.getBonus());
textDescuentos.setText(profile.getDiscounts());
textPendientesPago.setText(profile.getPending());
textTotal.setText(profile.getTotal());
textEnviosDiarios.setText(profile.getDairy());
textEnviosQuincenales.setText(profile.getCycle());
textEnviosMensuales.setText(profile.getMonth());
}
espero y me puedan ayudar el error que obtengo es:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference at com.app99minutos.app99minutos.Views.ResumenFragment$3.onErrorResponse(ResumenFragment.java:258)
Cada vez que cambio de Fragment
se queda realizando la petición anterior pero como no tiene donde imprimir colapsa