I have been trying lately but I just can't find where is the null object, help me understanding this error:
2021-01-24 01:10:47.244 24211-24211/com.salmanibrahim.firebasechat E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.salmanibrahim.firebasechat, PID: 24211
java.lang.NullPointerException: Attempt to read from field 'java.lang.String com.salmanibrahim.firebasechat.model.User.name' on a null object reference
at com.salmanibrahim.firebasechat.ui.UserProfileFragment.setupArrayListInfo(UserProfileFragment.java:243)
at com.salmanibrahim.firebasechat.ui.UserProfileFragment$1.onDataChange(UserProfileFragment.java:93)
at com.google.firebase.database.Query$1.onDataChange(Query.java:189)
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:808)
at android.os.Handler.dispatchMessage(Handler.java:101)
at android.os.Looper.loop(Looper.java:166)
at android.app.ActivityThread.main(ActivityThread.java:7529)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:245)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:921)
(UserProfileFragment.java:243)
Configuration userNameConfig = new Configuration(USERNAME_LABEL, myAccount.name, R.mipmap.ic_account_box);
(UserProfileFragment.java:93)
setupArrayListInfo(myAccount);
The app runs correctly, login is succesfull but as soon as code reaches this point:
if (listFriendID == null) {
listFriendID = new ArrayList<>();
dialogFindAllFriend.setCancelable(false)
.setIcon(R.drawable.ic_add_friend)
.setTitle("Fetching Friends Data...")
.setTopColorRes(R.color.colorPrimary)
.show();
getListFriendUId();
}
Dialog Appears correctly but when it ends loading the app crashes then and there.
Implementation for getListFriendUId();
:
private void getListFriendUId() {
FirebaseDatabase.getInstance().getReference().child("friend/" + StaticConfig.UID).addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
if (dataSnapshot.getValue() != null) {
HashMap mapRecord = (HashMap) dataSnapshot.getValue();
Iterator listKey = mapRecord.keySet().iterator();
while (listKey.hasNext()) {
String key = listKey.next().toString();
listFriendID.add(mapRecord.get(key).toString());
}
getAllFriendInfo(0);
} else {
dialogFindAllFriend.dismiss();
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
I just can't figure out, where to look for error.