0
I’m having difficulty when I pass a dice using the put. Extras.
My app is crashing and I can’t identify the reason.
He is unable to pass the data from one Activity to another.
Activity that sends the data:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
edtNameField = (EditText) findViewById(R.id.edtName);
edtPhoneField = (EditText) findViewById(R.id.edtPhone);
edtCompanySettings = (EditText) findViewById(R.id.edtCompanySettings);
edtEmailSettings = (EditText) findViewById(R.id.edtEmailSettings);
pd = new SpotsDialog(this, R.style.CustomPD);
imgProfileImage = (ImageView) findViewById(R.id.imgProfileImage);
btnBack = (Button) findViewById(R.id.btnBack);
btnConfirm = (Button) findViewById(R.id.btnConfirm);
mAuth = FirebaseAuth.getInstance();
userID = mAuth.getCurrentUser().getUid();
mCustomerDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(userID);
getUserInfo();
imgProfileImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, 1);
}
});
btnConfirm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pd.show();
saveUserInformation();
//enviarDados();
enviarDadosShare();
Toast.makeText(SettingsActivity.this, "Os dados foram salvos!", Toast.LENGTH_LONG).show();
}
});
btnBack.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
return;
}
});
}
public void enviarDadosShare(){
Intent enviarDados = new Intent(this, TelaPrincipalActivity.class);
EditText nome = (EditText) findViewById(R.id.edtName);
SharedPreferences prefs = getSharedPreferences("preferencias",
Context.MODE_PRIVATE);
SharedPreferences.Editor ed = prefs.edit();
ed.putString("nome", nome.getText().toString());
ed.apply();
Toast.makeText(getBaseContext(), "Gravado com sucesso", Toast.LENGTH_SHORT).show();
enviarDados.putExtra("nome", nome.getText().toString());
startActivity(enviarDados);
}
I’m trying to pass the data to my side menu
This is my method to receive the data from the other Activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tela_principal);
inicializarComponentes();
inicializarFirebase();
eventoEdit();
receberDadosSahred();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
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.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}
public void receberDadosSahred(){
Intent intent2 = getIntent();
if (intent2 != null){
Bundle params = intent2.getExtras();
if (params != null){
TextView textView = (TextView) findViewById(R.id.textView);
String str = intent2.getStringExtra("nome");
textView.setText(str);
}
}
}
In debug mode:
Error that is presenting:
E/Androidruntime: FATAL EXCEPTION: main Process: homologa.cappta.com.br.capptahomologa, PID: 12973 java.lang.RuntimeException: Unable to start activity ComponentInfo{homologa.cappta.com.br.capptahomologa/homologa.cappta.com.br.capptahomologa.Activity.TelaPrincipalActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.TextView.setText(java.lang.Charsequence)' on a null Object Reference at android.app.Activitythread.performLaunchActivity(Activitythread.java:2830) at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2909) at android.app.Activitythread. -wrap11(Unknown Source:0) at android.app.Activitythread$H.handleMessage(Activitythread.java:1606) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.Activitythread.main(Activitythread.java:6592) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygote$Methodandargscaller.run(Zygote.java:240) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:769) Caused by: java.lang.Nullpointerexception: Attempt to invoke virtual method 'void android.widget.Textview.setText(java.lang.Charsequence)' on a null Object Reference at homologa.cappta.com.br.capptahomologa.Activity.Telaprincipalactivity.receivedSahred(Telaprincipalactivity.java:118) at homologa.cappta.com.br.capptahomologa.Activity.Telaprincipalactivity.onCreate(Telaprincipalactivity.java:91) at android.app.Activity.performCreate(Activity.java:6984) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1235) at android.app.Activitythread.performLaunchActivity(Activitythread.java:2783) at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2909) at android.app.Activitythread. -wrap11(Unknown Source:0) at android.app.Activitythread$H.handleMessage(Activitythread.java:1606) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.Activitythread.main(Activitythread.java:6592) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygote$Methodandargscaller.run(Zygote.java:240) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:769) E/UncaughtException: java.lang.RuntimeException: Unable to start activity ComponentInfo{homologa.cappta.com.br.capptahomologa/homologa.cappta.com.br.capptahomologa.Activity.TelaPrincipalActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Textview.setText(java.lang.Charsequence)' on a null Object Reference at android.app.Activitythread.performLaunchActivity(Activitythread.java:2830) at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2909) at android.app.Activitythread. -wrap11(Unknown Source:0) at android.app.Activitythread$H.handleMessage(Activitythread.java:1606) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.Activitythread.main(Activitythread.java:6592) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygote$Methodandargscaller.run(Zygote.java:240) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:769) Caused by: java.lang.Nullpointerexception: Attempt to invoke virtual method 'void android.widget.Textview.setText(java.lang.Charsequence)' on a null Object Reference at homologa.cappta.com.br.capptahomologa.Activity.Telaprincipalactivity.receivedSahred(Telaprincipalactivity.java:118) at homologa.cappta.com.br.capptahomologa.Activity.Telaprincipalactivity.onCreate(Telaprincipalactivity.java:91) at android.app.Activity.performCreate(Activity.java:6984) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1235) at android.app.Activitythread.performLaunchActivity(Activitythread.java:2783) at android.app.Activitythread.handleLaunchActivity(Activitythread.java:2909) at android.app.Activitythread. -wrap11(Unknown Source:0) at android.app.Activitythread$H.handleMessage(Activitythread.java:1606) at android.os.Handler.dispatchMessage(Handler.java:105) at android.os.Looper.loop(Looper.java:164) at android.app.Activitythread.main(Activitythread.java:6592) at java.lang.reflect.Method.invoke(Native Method) at com.android.Internal.os.Zygote$Methodandargscaller.run(Zygote.java:240) at com.android.Internal.os.Zygoteinit.main(Zygoteinit.java:769) Application terminated.
I made the change, but still keeps crashing the app :(
– Edimilson
Same error? Have ctz? Take a look at Logcat if the error is the same
– Leonardo Dias
TextView nomeView = (TextView) findViewById(R.id.emailPrincipal);
– Eduardo Dornel