navigation between fragments issue -


hi have problem buttom, have main drawer open main fragment, every time change fragment called addtobackstack(null) problem navigation drawer when im on second fragment , select fisrt option on drawer, fragment show properly, after press buttom , got :

01-24 18:40:16.522 12825-12825/? e/androidruntime: fatal exception: main process: ar.com.taxiexpress.taxiexpress, pid: 12825 android.view.inflateexception: binary xml file line #6: error inflating class fragment @ android.view.layoutinflater.createviewfromtag(layoutinflater.java:713) @ android.view.layoutinflater.rinflate(layoutinflater.java:755) @ android.view.layoutinflater.inflate(layoutinflater.java:492) @ android.view.layoutinflater.inflate(layoutinflater.java:397) @ ar.com.taxiexpress.taxiexpress.mapachofer.oncreateview(mapachofer.java:80) @ android.support.v4.app.fragment.performcreateview(fragment.java:1962) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1067) @ android.support.v4.app.fragmentmanagerimpl.movetostate(fragmentmanager.java:1248)...

here ist code:

main drawer:

public class drawerprincipal extends appcompatactivity         implements navigationview.onnavigationitemselectedlistener,fragmentoprincipalusuario.onfragmentinteractionlistener {       private parsefile mprueba;     private uri url;     private imageview imagen;     sharedpreferences sharedpref;     sharedpreferences.editor  loginstateeditor ;        @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_drawer_principal);         toolbar toolbar = (toolbar) findviewbyid(r.id.toolbar);         setsupportactionbar(toolbar);           parseuser usuario= parseuser.getcurrentuser();     if(usuario==null){         intent intento=new intent(this,actividadlogin.class);         intento.addflags(intent.flag_activity_new_task);         intento.addflags(intent.flag_activity_clear_task);         startactivity(intento);      }              drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);         actionbardrawertoggle toggle = new actionbardrawertoggle(                 this, drawer, toolbar, r.string.navigation_drawer_open, r.string.navigation_drawer_close);         drawer.setdrawerlistener(toggle);         toggle.syncstate();          navigationview navigationview = (navigationview) findviewbyid(r.id.nav_view);         navigationview.setnavigationitemselectedlistener(this);          view hview =  navigationview.inflateheaderview(r.layout.nav_header_drawer_principal);         final imageview imgvw = (imageview)hview.findviewbyid(r.id.imagenperfil);         final textview tv = (textview)hview.findviewbyid(r.id.nombreusuariov);         //picasso.with(getbasecontext()).load(url.tostring()).into(imgvw);         tv.settext("new text");          parsequery<parseuser> query2 = parseuser.getquery();         query2.whereequalto("username","gaspar@gmail.com");         query2.findinbackground(new findcallback<parseuser>() {             public void done(list<parseuser> usuario, parseexception e) {                 if (e == null) {                      mprueba = usuario.get(0).getparsefile("foto");                     tv.settext(usuario.get(0).getusername().tostring());                     url = uri.parse(mprueba.geturl());                     picasso.with(getbasecontext()).load(url.tostring()).transform(new roundedtransformation(300, 4)).into(imgvw);                   } else {                     // went wrong.                 }             }         });             //fragmento del chofer                 fragment fragmento;             fragmento = new fragmentoprincipalchofer();             getsupportfragmentmanager().begintransaction()                     .replace(r.id.content_main, fragmento)                     .commit();         }           @override     public boolean oncreateoptionsmenu(menu menu) {         // inflate menu; adds items action bar if present.         getmenuinflater().inflate(r.menu.pantalla_principal_usuario, menu);         return true;     }      @override     public boolean onoptionsitemselected(menuitem item) {         // handle action bar item clicks here. action bar         // automatically handle clicks on home/up button, long         // specify parent activity in androidmanifest.xml.         int id = item.getitemid();          //noinspection simplifiableifstatement         if (id == r.id.action_settings) {             return true;         }          return super.onoptionsitemselected(item);     }      @suppresswarnings("statementwithemptybody")     @override     public boolean onnavigationitemselected(menuitem item) {         // handle navigation view item clicks here.         int id = item.getitemid();          if (id == r.id.cuenta) {              fragment fragmento;             fragmento = new opciondrawerusuario();             getsupportfragmentmanager().begintransaction()                     .replace(r.id.content_main, fragmento)                     .addtobackstack(null)                     .commit();          } else if (id == r.id.historial_viajes) {             fragment fragmento;             fragmento = new fragmentoviajesacumulados();             getsupportfragmentmanager().begintransaction()                     .replace(r.id.content_main, fragmento)                     .commit();           } else if (id == r.id.contacto) {             string emailadress[] = {"gastondelacruz@gmail.com"};             intent email= new intent(intent.action_send);             email.putextra(intent.extra_email,emailadress);             email.putextra(intent.extra_subject,"pon aqui el motivo de tu mail");             email.settype("text/plain");             email.putextra(intent.extra_text,"su mensaje");             startactivity(email);           } else if (id == r.id.compartir) {             string texto="https://www.google.com.ar/?gfe_rd=cr&ei=9jubvvmcganx8gejsk_4ca&gws_rd=ssl";             intent intento= new intent();             intento.setaction(intent.action_send);             intento.putextra(intent.extra_text, texto);             intento.settype("text/plain");             startactivity(intento);          } else if (id == r.id.version) {             string prueba="aceptar";             alertdialog.builder builder = new alertdialog.builder(this);             builder.settitle("prueba") //                     .setmessage("esta es una prueba todavia no poseo el numero de version del producto") //                     .setpositivebutton(prueba, new dialoginterface.onclicklistener() {                         public void onclick(dialoginterface dialog, int id) {                             // todo                             dialog.dismiss();                         }                     }); //              builder.show();          } else if (id == r.id.salir) {              finish();         }          drawerlayout drawer = (drawerlayout) findviewbyid(r.id.drawer_layout);         drawer.closedrawer(gravitycompat.start);         return true;     } 

}

main fragment:

public class fragmentoprincipalchofer extends listfragment {     private list<parseobject> mpedido;     private list<parseobject> mviaje;     private list<parseuser> murlusuario;     private listview mlista;     private runnable r;     final handler handler = new handler();          public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {           view x = inflater.inflate(r.layout.fragmento_principal_chofer, container, false);         mlista = (listview)x.findviewbyid(android.r.id.list);          return x;      }      @override     public void onresume() {         super.onresume();           // logica de recibir pedidos                r = new runnable() {                 public void run() {                      handler.postdelayed(r, 10000);                         //obtener pedido de taxi                     parsequery<parseobject> query = parsequery.getquery("pedido");                     query.whereequalto("chofer", "chofer1");                     query.adddescendingorder("createdat");                     query.findinbackground(new findcallback<parseobject>() {                         public void done(list<parseobject> pedido, com.parse.parseexception e) {                             if (e == null) {                                 mpedido = pedido;                                 string[] nombreusuarios = new string[mpedido.size()];                                 int = 0;                                 (parseobject pedidos : mpedido) {                                      nombreusuarios[i] = pedidos.getstring("cliente");                                     i++;                                  }                                    adaptadordatoslistviewchofer adaptador = new adaptadordatoslistviewchofer(getlistview().getcontext(), mpedido);                                 setlistadapter(adaptador);                              } else {                              }                         }                     });                  }             };             r.run();               clickpedido();        }    // manejo de click sobre el pedido de taxi     public void clickpedido(){          mlista.setonitemclicklistener(new adapterview.onitemclicklistener() {             @override             public void onitemclick(adapterview<?> parent, view view, int position, long id) {                  fragment fragment2 = new mapachofer();                 fragmenttransaction transaction = getchildfragmentmanager().begintransaction();                 transaction.replace(r.id.prueba2, fragment2).addtobackstack(null);                 transaction.commit(); /*                 drawerprincipal prueba=new drawerprincipal();                 prueba.cambiarfragmento();*/                   //verificar si aun existe el pedido en la base de datos                /* final string clienteseleccionado = (string) mlista.getitematposition(position);                 parsequery<parseobject> query = parsequery.getquery("pedido");                 query.whereequalto("usuario", clienteseleccionado);                 query.findinbackground(new findcallback<parseobject>() {                     public void done(list<parseobject> pedido, com.parse.parseexception e) {                         if (e == null) {                             //guardar viaje tomado por chofer                             parseobject viaje = new parseobject("viaje");                             viaje.put("chofer", "chofer1");                             viaje.put("cliente", clienteseleccionado);                             viaje.saveinbackground();                               //borrar pedido xque paso viaje                               parsequery<parseobject> query = new parsequery<parseobject>("pedido");                             query.whereequalto("cliente", clienteseleccionado);                             query.getfirstinbackground(new getcallback<parseobject>() {                                 @override                                 public void done(parseobject pedido, parseexception e) {                                     try {                                         pedido.delete();                                         pedido.saveinbackground();                                     } catch (parseexception ex) {                                         ex.printstacktrace();                                     }                                 }                             });                          } else {                             //debo cambiarlo por un dialog                             toast.maketext(getcontext(), "el pedido ya fue tomado", toast.length_long).show();                         }                     }                 });*/              }         });       }     @override     public void onpause() {         super.onpause();         handler.removecallbacks(r);     }  } 

second fragment:

   public class mapachofer extends fragment implements onmapreadycallback {      private supportmapfragment smapfragment;     private runnable r;     final handler handler = new handler();     private string mdireccion;     private googlemap mmapataxi;     private marker mmarcadortaxi;     private marker mmarcadorcliente;     public boolean mcambiarposicion = false;     private button mcancelar;     private button mtomado;     private parsefile mprueba;     private uri url;     private imageview musuario;     private textview mnusuario;     private double mlatitud;     private double mlongitud;     private double mlatitudcliente;     private double mlongitudcliente;       @override     public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {          //conseguir usuario actual         // musuarioactual = parseuser.getcurrentuser();          //preparar google maps         final view x = inflater.inflate(r.layout.mapa_chofer, container, false);         mcancelar = (button) x.findviewbyid(r.id.cancelarpedido);         mtomado = (button) x.findviewbyid(r.id.ptomadobtn);         musuario = (imageview) x.findviewbyid(r.id.usuarioiv);         mnusuario = (textview) x.findviewbyid(r.id.usuariontv);         mtomado.setenabled(false);          parseuser currentuser = parseuser.getcurrentuser();         currentuser.logout();          parseuser.logininbackground("chofer1", "12345", new logincallback() {             public void done(parseuser user, parseexception e) {                 if (user != null) {                     // hooray! user logged in.                 } else {                     // signup failed. @ parseexception see happened.                 }             }         });           parsequery<parseuser> query2 = parseuser.getquery();         query2.whereequalto("username", "gaspar@gmail.com");         query2.findinbackground(new findcallback<parseuser>() {             public void done(list<parseuser> usuario, parseexception e) {                 if (e == null) {                      mprueba = usuario.get(0).getparsefile("foto");                     mnusuario.settext(usuario.get(0).getusername().tostring());                     url = uri.parse(mprueba.geturl());                     picasso.with(getcontext()).load(url.tostring()).transform(new roundedtransformation(300, 4)).into(musuario);                   } else {                     // went wrong.                 }             }         });           smapfragment = supportmapfragment.newinstance();         smapfragment.getmapasync(this);         android.support.v4.app.fragmentmanager fm = getfragmentmanager();         android.support.v4.app.fragmentmanager sfm = getchildfragmentmanager();         sfm.begintransaction().add(r.id.mapachofer, smapfragment).commit();           //controlar pedido          seguirpedido();                   return x;      }       public void seguirpedido() {           // mmarcadortaxi = mmapataxi.addmarker(new markeroptions().position(sydney));         r = new runnable() {             public void run() {                  handler.postdelayed(r, 10000);                 parsequery<parseuser> query = parseuser.getquery();                 query.whereequalto("username", "chofer1");                 query.findinbackground(new findcallback<parseuser>() {                     public void done(final list<parseuser> objects, parseexception e) {                         if (e == null) {                             double longitud = double.parsedouble(objects.get(0).get("longitud").tostring());                             double latitud = double.parsedouble(objects.get(0).get("latitud").tostring());                                if (mcambiarposicion == true) {                                  //obtener la posicion actual                                 posicionactual();                                    final parseuser usuario = parseuser.getcurrentuser();                                 usuario.put("longitud", mlongitud);                                 usuario.put("latitud", mlatitud);                                 usuario.saveinbackground(new savecallback() {                                     @override                                     public void done(parseexception e) {                                         if (e == null) {                                             //success, saved!                                          } else {                                             //fail save!                                          }                                     }                                 });                                    mmarcadortaxi.remove();                                 latlng posiciontaxista = new latlng(mlatitud, mlongitud);                                 mmarcadortaxi = mmapataxi.addmarker(new markeroptions().position(posiciontaxista));                                   location prueba1 = new location("punto a");                                 prueba1.setlongitude(mlongitud);                                 prueba1.setlatitude(mlatitud);                                  location prueba2 = new location("punto a");                                 prueba2.setlongitude(mlongitudcliente);                                 prueba2.setlatitude(mlatitudcliente);                                    float distance;                                 distance = prueba1.distanceto(prueba2);                                   if (distance < 300) {                                     toast.maketext(getcontext(), "el taxi se encuentra 1 cuadra", toast.length_long).show();                                     mtomado.setenabled(true);                                     mtomado.setonclicklistener(new view.onclicklistener() {                                         @override                                         public void onclick(view v) {                                             getfragmentmanager().popbackstack();                                           }                                     });                                 }                               } else {                                 posicionactual();                                 latlng posiciontaxista = new latlng(mlatitud,mlongitud );                                 mmarcadortaxi = mmapataxi.addmarker(new markeroptions().position(posiciontaxista));                               }                              // handler.removecallbacks(r);                             // mtomado=true;                             // toast.maketext(getcontext(),mlongitud+"",toast.length_long).show();                             mcambiarposicion = true;                         } else {                             // went wrong.                         }                     }                 });               }         };         r.run();       }     // mmarcadortaxi.remove();       @override     public void onmapready(final googlemap googlemap) {          if (activitycompat.checkselfpermission(getcontext(), android.manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(getcontext(), android.manifest.permission.access_coarse_location) != packagemanager.permission_granted) {             // todo: consider calling             //    activitycompat#requestpermissions             // here request missing permissions, , overriding             //   public void onrequestpermissionsresult(int requestcode, string[] permissions,             //                                          int[] grantresults)             // handle case user grants permission. see documentation             // activitycompat#requestpermissions more details.             return;         }         googlemap.setmylocationenabled(true);         double longitud=-27.793483;         double latitud=-64.257572;         final latlng ubicacion = new latlng(latitud,longitud );         googlemap.movecamera(cameraupdatefactory.newlatlngzoom(ubicacion,14 ));         mmapataxi = googlemap;            parsequery<parseuser> query = parseuser.getquery();         query.whereequalto("username", "gaspar@gmail.com");         query.findinbackground(new findcallback<parseuser>() {             @override             public void done(list<parseuser> objects, parseexception e) {                 double longitud = double.parsedouble(objects.get(0).get("longitud").tostring());                 double latitud = double.parsedouble(objects.get(0).get("latitud").tostring());                   final latlng ubicacion = new latlng(latitud,longitud );                 float zoomlevel = 14;                 mmarcadorcliente = googlemap.addmarker(new markeroptions().position(ubicacion).title("este es el cliente"));                 googlemap.movecamera(cameraupdatefactory.newlatlngzoom(ubicacion, zoomlevel));                  mlongitudcliente=longitud;                 mlatitudcliente=latitud;              }         });               }        public void posicionactual() {         locationmanager mng = (locationmanager) getcontext().getsystemservice(getcontext().location_service);         if (activitycompat.checkselfpermission(getcontext(), android.manifest.permission.access_fine_location) != packagemanager.permission_granted && activitycompat.checkselfpermission(getcontext(), android.manifest.permission.access_coarse_location) != packagemanager.permission_granted) {             // todo: consider calling             //    activitycompat#requestpermissions             // here request missing permissions, , overriding             //   public void onrequestpermissionsresult(int requestcode, string[] permissions,             //                                          int[] grantresults)             // handle case user grants permission. see documentation             // activitycompat#requestpermissions more details.             return;         }         location location1 = mng.getlastknownlocation(mng.getbestprovider(new criteria(), false));         mlatitud =  location1.getlatitude();         mlongitud = location1.getlongitude();      }       @override     public void onresume() {         super.onresume();          getview().setfocusableintouchmode(true);         getview().requestfocus();         getview().setonkeylistener(new view.onkeylistener() {             @override             public boolean onkey(view v, int keycode, keyevent event) {                  if (event.getaction() == keyevent.action_up && keycode == keyevent.keycode_back) {                     getfragmentmanager().popbackstack();                     return true;                 }                 return false;             }         });     } } 

first drawer option fragment:

public class opciondrawerusuario extends fragment {     private textview nombre;     private textview pass;     private button guardar;     private button salir;     private fragmentoprincipalchofer hilo=new fragmentoprincipalchofer();      public view oncreateview(layoutinflater inflater, viewgroup container,                              bundle savedinstancestate) {          //conseguir usuario actual         // musuarioactual = parseuser.getcurrentuser();           view x = inflater.inflate(r.layout.opcion_drawer_usuario, container, false);         nombre=(textview)x.findviewbyid(r.id.nombretv);         pass=(textview)x.findviewbyid(r.id.passtv);         guardar=(button)x.findviewbyid(r.id.guardarbuttom);         salir=(button)x.findviewbyid(r.id.volverbuttom);           //cargar datos usuario           parsequery<parseuser> query = parseuser.getquery();         query.whereequalto("username", "usuario1");         query.findinbackground(new findcallback<parseuser>() {             public void done(list<parseuser> usuario, parseexception e) {                 if (e == null) {                      nombre.settext(usuario.get(0).getusername());                    } else {                     // went wrong.                 }             }         });           guardar.setonclicklistener(new view.onclicklistener() {             @override          public void onclick(view v) {              }         });           // inflate layout fragment         return x;      }      @override     public void onresume() {         super.onresume();          getview().setfocusableintouchmode(true);         getview().requestfocus();         getview().setonkeylistener(new view.onkeylistener() {             @override             public boolean onkey(view v, int keycode, keyevent event) {                  if (event.getaction() == keyevent.action_up && keycode == keyevent.keycode_back) {                     getfragmentmanager().popbackstack();                     return true;                 }                 return false;             }         });     }  } 

i resolve issue with:

if (mview != null) {             viewgroup parent = (viewgroup) mview.getparent();             if (parent != null)                 parent.removeview(mview);         }         try {   } catch (inflateexception e) {             e.printstacktrace();         } 

Comments