无法解决或理解造成此错误的确切原因是什么?

时间:2019-12-28 12:56:15

标签: android firebase android-intent google-cloud-firestore

这是我收到的错误消息

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Intent.getStringExtra(java.lang.String)' on a null object reference
        at com.example.authenticatorapp.MessageActivity.<init>(MessageActivity.java:36)

这是36行显示的代码行

String recipientId = getIntent().getStringExtra("recipientId");
DocumentReference recipientReference = FirebaseFirestore.getInstance().collection("users").document(recipientId);

这是上述getStringExtra()的putStringExtra()

@Override
    protected void onBindViewHolder(@NonNull ViewHolder holder, int position, @NonNull final User model) {
        holder.fName.setText(model.getfName());
        holder.profile_image.setImageResource(R.mipmap.ic_launcher);
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(v.getContext(), MessageActivity.class);
                intent.putExtra("recipientId", model.getUserId());
                v.getContext().startActivity(intent);
            }
        });
    }

这将是我使用的收件人参考

recipientReference.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
            @Override
            public void onComplete(@NonNull Task<DocumentSnapshot> task) {
                if (task.isSuccessful()) {
                    DocumentSnapshot document = task.getResult();
                    if (document.exists()) {
                        Log.d(TAG, "DocumentSnapshot data: " + document.getData());
                        User user = document.toObject(User.class);
                        username.setText(user.getfName());
                    } else {
                        Log.d(TAG, "No such document");
                    }
                } else {
                    Log.d(TAG, "get failed with ", task.getException());
                }
            }
        });

Database

0 个答案:

没有答案