android activity call to fragment

1

I have an activity from which I upload a fragment or another by clicking on a notification. The code is as follows:

public class Repeating_activity extends AppCompatActivity {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    Bundle intent = getIntent().getExtras();

    String tipoNotificacion = intent.getString("tipoNotificacion");

    if(tipoNotificacion.equals("1")){
        lanzarFragmentoMantenimientosVencidos();
    } else if(tipoNotificacion.equals("2")){
        lanzarFragmentoInspeccionesVencidas();
    }
}

private void lanzarFragmentoMantenimientosVencidos(){
    Mantenimientos_fragment mpf = new Mantenimientos_fragment();
    Bundle bundle = new Bundle();
    bundle.putInt("filtro", 2);
    mpf.setArguments(bundle);
    getFragmentManager().beginTransaction().replace(R.id.flContenedor, mpf).addToBackStack(null).commit();
}
private void lanzarFragmentoInspeccionesVencidas(){
    Inspecciones_fragment ipf = new Inspecciones_fragment();
    Bundle bundle = new Bundle();
    bundle.putInt("filtro", 2);
    ipf.setArguments(bundle);
    getFragmentManager().beginTransaction().add(R.id.flContenedor, ipf).addToBackStack(null).commit();
 }
}

Debugging, it does not reach any class of any fragment and I get the following errors:

05-28 11:44:43.706 3922-3922/com.kastel.COSMA E/FragmentManager: No view found for id 0x7f080082 (com.kastel.COSMA:id/flContenedor) for fragment Mantenimientos_fragment{5c9c505 #1 id=0x7f080082}

-

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.kastel.COSMA/com.kastel.COSMA.notificaciones.Repeating_activity}: java.lang.IllegalArgumentException: No view found for id 0x7f080082 (com.kastel.COSMA:id/flContenedor) for fragment Mantenimientos_fragment{5c9c505 #1 id=0x7f080082}
    
asked by Juan 28.05.2018 в 13:47
source

1 answer

2

The problem that is shown is because you can not find the view where to make the Fragment transaction:

  

FragmentManager: No view found for id 0x7f080082   (com.kastel.COSMA: id / flContainer) for fragment   Maintenance_fragment {5c9c505 # 1

R.id.flContenedor does not exist in the layout you load in Activity with setContentView()

You can add a FrameLayout in the layout with id flContenedor and this would show your Fragment .

    
answered by 28.05.2018 / 16:11
source