I will add data to database when I register, but I got
Java.lang.NullPointerException: Attempt to invoke virtual method \'java.lang.String com.google.firebase.auth.
FirebaseUser user = auth.getCurrentUser();
userID = user.getUid();
To run above two lines, you must (I'm stressing you must) have username/password based authenticated in the Firebase. It is throwing NullPointerException
because most of the novice programmer forget to setup user based authentication in Firebase console.
You can add the user in Firebase Authentication.
If you are using Firebase Realtime Database then I suggest you add following rules in RULES tab.
// These rules grant access to a node matching the authenticated
// user's ID from the Firebase auth token
{
"rules": {
"users": {
"$user_id": {
".read": "$user_id === auth.uid",
".write": "$user_id === auth.uid"
}
}
}
}