//initiate the firebase
mAuth = FirebaseAuth.getInstance();
//check if user sign out
if(mAuth.getCurrentUser() == null){
finish();
startActivity(new Intent(this, Iniciar.class));
}
// get the phone of current user
FirebaseUser user = mAuth.getCurrentUser();
String email = user.getEmail();
String [] parts = email.split("a");
ownPhone = parts[0];
// get the database reference of current user
DatabaseReference mCurrentUser = mPhoneNo.child(ownPhone);
DatabaseReference mFirstName = mCurrentUser.child("firstName");
DatabaseReference mBalance = mCurrentUser.child("balanceAmount");
balance = (TextView) findViewById(R.id.balance);
listView = (ListView)findViewById(R.id.list);
listView.setAdapter(new ListAdapter(listFrame, listIcon) {
});
** Y este es parte de mi codigo**
Y donde me marca el error, ahi estoy tratando de obtener el nombre de usuario para que salga a un costado en la app, cuando el user ya este el home activity`
//retrieve the Name of User from database in realtime
mFirstName.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String tvname = dataSnapshot.getValue(String.class);
Log.i(TAG,tvname);
tranUserNameText.setText(tvname);
}
@Override
public void onCancelled(DatabaseError databaseError) {
//Toast.makeText(Transaction.this, "Cannot find your name",Toast.LENGTH_SHORT).show();
}
});
java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.i(Log.java:176)
at com.example.vepago14.Transaction$3.onDataChange(Transaction.java:153)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:75)
at com.google.firebase.database.core.view.DataEvent.fire(DataEvent.java:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(EventRaiser.java:55)
at android.os.Handler.handleCallback(Handler.java:883)
at android.os.Handler.dispatchMessage(Handler.java:100)
at android.os.Looper.loop(Looper.java:221)
at android.app.ActivityThread.main(ActivityThread.java:7542)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:539)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:950)
Y este es el error que me sale, dice que en " Log.i(TAG,tvname);" se esta devolviendo como null y me saca de la app, y la verdad no se que tengo malo ahi, y en el android studio no me dice exactamente cual es el eror