- Logcat
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String com.google.firebase.auth.FirebaseUser.getUid()' on a null object reference at com.example.medcareinapp.UserSideScreens.PatientDashboardActivity.onCreate(PatientDashboardActivity.java:89)
- PatientDashboardActivity.java
private static FirebaseAuth mAuth; public static String UserName;
DrawerLayout drawerLayout;
TextView nav_name;
CardView bookRideCard, profileCard, activeRideCard, historyCard, book_doctor, active_appointments;
Intent i;
FirebaseFirestore firebaseFirestore;
FirebaseAuth firebaseAuth;
String currentUserKey;
private int PERMISSION_CODE = 1;
//shared prefs variables
public static final String SHARED_PREFS = "SharedPrefs";
public static final String userType = "userType";
public static final String userNodeKey = "userKey";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_patient_dashboard);
// check if the permissions are granted
if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(PatientDashboardActivity.this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, PERMISSION_CODE);
Toast.makeText(getApplicationContext(), "Provide the permissions to continue", Toast.LENGTH_SHORT).show();
return;
}
SharedPreferences sharedPreferences = getSharedPreferences(SHARED_PREFS, MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
firebaseAuth = FirebaseAuth.getInstance();
firebaseFirestore = FirebaseFirestore.getInstance();
currentUserKey = firebaseAuth.getCurrentUser().getUid();
mAuth = FirebaseAuth.getInstance();
UserName = getIntent().getStringExtra("UserName");
drawerLayout = findViewById(R.id.drawer);
nav_name = findViewById(R.id.nav_name);
nav_name.setText(UserName);
book_doctor = findViewById(R.id.book_doctor);
active_appointments = findViewById(R.id.active_appointments);
bookRideCard = findViewById(R.id.bookRideCardPDashboard);