Home > database >  Cannot resolve method 'collection' in 'FirebaseStorage'
Cannot resolve method 'collection' in 'FirebaseStorage'

Time:11-17

i want to accsess my firebase collection but somehow it didnt work on this java file, in otherwise i had another java file on my android project thats containts the same syntax and its actually work.. i dont have any idea to solve this line

on Signupn.java (worked)

fAuth.createUserWithEmailAndPassword(email, password)
                    .addOnCompleteListener(new OnCompleteListener<AuthResult>() {
                @Override
                public void onComplete(@NonNull Task<AuthResult> task) {
                    if (task.isSuccessful()) {
                        Toast.makeText(SignUp.this, "User Created", Toast.LENGTH_SHORT).show();
                        userId = fAuth.getCurrentUser().getUid();
                        DocumentReference documentReference =fStore.collection("users").document(userId);
                        Map<String,Object> user =new HashMap<>();
                        user.put("fName",fullName);
                        user.put("email",email);
                        user.put("phone",phone);
                        documentReference.set(user).addOnSuccessListener(new OnSuccessListener<Void>() {
                            @Override
                            public void onSuccess(Void unused) {
                                Log.d(TAG,"onSuccess: user Profile is created for "  userId);
                            }
                        });
                        startActivity(new Intent(getApplicationContext(), MainActivity.class));
                    }else{
                        Toast.makeText(SignUp.this, "Error!" task.getException().getMessage(), Toast.LENGTH_SHORT).show();
                        progressBar.setVisibility(View.GONE);
                    }
                }
            });

on EditProfile.java (error)

 saveBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (editFullName.getText().toString().isEmpty() || editEmail.getText().toString().isEmpty()
                        || editPhone.getText().toString().isEmpty()) {
                    Toast.makeText(EditProfile.this, "All Fields Are Required.", Toast.LENGTH_SHORT).show();
                    return;
                }

                String email = editEmail.getText().toString();
                user.updateEmail(email).addOnSuccessListener(new OnSuccessListener<Void>() {
                    @Override
                    public void onSuccess(Void unused) {
                        DocumentReference docRef = fStore.collection("users").document(user.getUid());
                        Map<String, Object> edited = new HashMap<>();
                        edited.put("email", email);
                        edited.put("fName", editFullName.getText().toString());
                        edited.put("phone", editPhone.getText().toString());
                        docRef.update(edited);
                        Toast.makeText(EditProfile.this, "Email Changed Successfully.", Toast.LENGTH_SHORT).show();
                    }
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Toast.makeText(EditProfile.this, "Error!", Toast.LENGTH_SHORT).show();
                    }
                });
            }
        });

here is where the error line

DocumentReference docRef = fStore.collection("users").document(user.getUid());

in collection sentence.

this picture from editProfile.java

this picture from signup.java

thank you for your value answers, any answer i really apriciate it.

CodePudding user response:

Please verify your dataStype for fstore object in both classes or post full code wherever you are declaring the fstore and intializing it

  • Related