Is there any way to retrieve the data from firestore in Maps. I am trying but its returning null here is my code
docRef = db.collection("Buses").document("Bus1"); Button btn=view.findViewById(R.id.submit); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() { @Override public void onSuccess(DocumentSnapshot documentSnapshot) { bus=documentSnapshot.getData(); } }); if (!bus.get("ID").toString().matches(busId)) { DocumentReference reference = db.collection("Buses").document("Bus2"); reference.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() { @Override public void onSuccess(DocumentSnapshot documentSnapshot) { bus=documentSnapshot.getData(); } }); } if (bus!=null){ Toast.makeText(getContext(), "Data read Successfully", Toast.LENGTH_SHORT).show(); Intent intent=new Intent(getContext(),MapsActivity.class); startActivity(intent); CONSTANTS.bus=HomeFragment.this.bus; getActivity().finishAffinity(); } else{ Toast.makeText(getContext(), "Data read Failed", Toast.LENGTH_SHORT).show(); } } }); But I am getting NullPointerException here Here is the screenshot of the database
I am not getting i why getdata function is returning null Here is the error log
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.Map.get(java.lang.Object)' on a null object reference at com.integratedsoftsols.fyp.bustracking.user.HomeFragment$1.onClick(HomeFragment.java:53) at android.view.View.performClick(View.java:6274) at android.view.View$PerformClick.run(View.java:24859) at android.os.Handler.handleCallback(Handler.java:789) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6710) 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:770) 