Android: NullPointerException in .getIntent (). getExtras ()


I'm in an android class project and I have it almost finished but I need to pass some variables from one activity to another, it gives me NullPointerException and looking for I have not found anything.




Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Bundle android.content.Intent.getExtras ()' on a null object reference                                                                              at com.grupo3.cebancburger.AnadirHamburguesa. (

The intent that I do in class.


(The views)

nomb = (EditText)findViewById(;
dire = (EditText)findViewById(;
tele = (EditText)findViewById(;
email = (EditText)findViewById(;


intent = new Intent(DatosCliente.this, AnadirHamburguesa. 
intent.putExtra("nombre", nomb.getText().toString());
intent.putExtra("direccion", dire.getText().toString());
intent.putExtra("telefono", tele.getText().toString());
intent.putExtra("email", email.getText().toString());

Add Hamburg (the getIntent)

Bundle extras = getIntent().getExtras();
String nom = extras.getString("nombre");
String dire = extras.getString("direccion");
String tele = extras.getString("telefono");
String email = extras.getString("email");
asked by Aritzbn 11.01.2018 в 19:32

1 answer


Try to retrieve the information in your activity Add Hamburg without using Bundle, as follows

Add Hamburg

Intent intent = getIntent();
String nombre = intent.getStringExtra("nombre");
String dire = intent.getStringExtra("direccion");    

If you use Bundle to pass data you must create the Bundle and pass it in the intent

Bundle bundle = new Bundle();
Intent intent = new Intent(DatosCliente.this, AnadirHamburguesa.class)

In Adding Hamburg

Bundle extras = getIntent().getExtras();
String nom = extras.getString("nombre");

In the future try to use Parcelable or Serializable to pass objects from one activity to another. For example, if you have a Client-type object that implements the Parcelable class

Cliente cliente = new Cliente(nombre,direccion);

Intent intent = new Intent(getApplicationContext(, SigActividad.class);
intent.putExtra("cliente", cliente);

In SigActivity:

Cliente cliente = getIntent().getExtras().getParcelable("nombre");
answered by 11.01.2018 / 19:39