'Unable to start activity ComponentInfo: java.lang.NullPointerException: Provided document path must not be null

public class ReplyActivity extends AppCompatActivity {

String uid,question,key,privacy;
FirebaseFirestore db = FirebaseFirestore.getInstance();
DocumentReference reference,reference2;

TextView nametv,questiontv,tvreply;
RecyclerView recyclerView;
ImageView imageViewQue,imageViewUser;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_reply);

    nametv=findViewById(R.id.name_reply_tv);
    questiontv=findViewById(R.id.que_reply_tv);
    imageViewQue=findViewById(R.id.iv_que_user);
    imageViewUser=findViewById(R.id.iv_reply_user);
    tvreply=findViewById(R.id.answer_tv);

    Bundle extra=getIntent().getExtras();
    if(extra != null){
        uid=extra.getString("uid");
        key=extra.getString("key");
        question=extra.getString("q");
        privacy=extra.getString("privacy");

    }else{
        Toast.makeText(this, "oops", Toast.LENGTH_SHORT).show();
    }

    FirebaseUser user=FirebaseAuth.getInstance().getCurrentUser();
    String currentuid=user.getUid();

    reference = db.collection("user").document(uid);
    reference2= db.collection("user").document(currentuid);


    tvreply.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    });


}

@Override
protected void onStart() {
    super.onStart();

    reference.get()
            .addOnCompleteListener((task) ->{
                if (task.getResult().exists()){
                    String url =task.getResult().getString("url");
                    String name =task.getResult().getString("name");
                    Picasso.get().load(url).into(imageViewQue);
                    questiontv.setText(question);
                    nametv.setText(name);
                }else{
                    Toast.makeText(ReplyActivity.this,"Error",Toast.LENGTH_SHORT).show();
                }
            } );

    reference2.get()
            .addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
                @Override
                public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                    {
                        if (task.getResult().exists()){
                            String url =task.getResult().getString("url");
                            Picasso.get().load(url).into(imageViewQue);
                        }else{
                            Toast.makeText(ReplyActivity.this,"Error",Toast.LENGTH_SHORT).show();
                        }
                }
            }
            } );
}

}

logcat : Process: com.rnz.ggistudentapp, PID: 30173 java.lang.RuntimeException: Unable to start activity ComponentInfo{com.rnz.ggistudentapp/com.rnz.ggistudentapp.ReplyActivity}: java.lang.NullPointerException: Provided document path must not be null. at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3735) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3903) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2328)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source