Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/186.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 应用程序未从Firestore检索文档_Java_Android_Firebase_Google Cloud Firestore - Fatal编程技术网

Java 应用程序未从Firestore检索文档

Java 应用程序未从Firestore检索文档,java,android,firebase,google-cloud-firestore,Java,Android,Firebase,Google Cloud Firestore,我想收集一些文件。文档应该从文档中获取名称和专业。但每次我运行应用程序时,文档都会被提取出来,并以列表的形式显示在recyclerView中,就像WhatsApp messenger中一样,但文本视图中不会显示字段。这是RecyclerView视图显示“CardView”的空白列表,没有文本,即我希望显示的名称和专业 以下是模型、适配器和活动的代码: 模型 public class Doctor { private String name; private String DoctorImage

我想收集一些文件。文档应该从文档中获取名称和专业。但每次我运行应用程序时,文档都会被提取出来,并以列表的形式显示在recyclerView中,就像WhatsApp messenger中一样,但文本视图中不会显示字段。这是RecyclerView视图显示“CardView”的空白列表,没有文本,即我希望显示的名称和专业

以下是模型、适配器和活动的代码:

模型

public class Doctor {

private String name;
private String DoctorImageURL;
private String specialty;

public Doctor() {
    //empty constructor needed
}

public Doctor(String name, String specialty) {
    this.name = name;
    this.specialty = specialty;
}

public String getmDoctorName() {
    return name;
}

public String getmDoctorSpecialty() {
    return specialty;
}
适配器

public class DoctorAdapter extends FirestoreRecyclerAdapter<Doctor, DoctorAdapter.DoctorHolder> {


public DoctorAdapter(@NonNull FirestoreRecyclerOptions<Doctor> options) {
    super(options);
}

@Override
protected void onBindViewHolder(@NonNull DoctorHolder doctorHolder, int i, @NonNull Doctor doctor) {

    doctorHolder.Name.setText(doctor.getmDoctorName());
    doctorHolder.Specialty.setText(doctor.getmDoctorSpecialty());

    //doctorHolder.DocImage.setImageResource(unifiedModel.getmDoctorImageURL());

    //Load images here

}

@NonNull
@Override
public DoctorHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

   View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.doctor_list_view_items,
           parent, false);

    return new DoctorHolder(view);
}

class DoctorHolder extends RecyclerView.ViewHolder{

    TextView Name, Specialty;
    ImageView DocImage;


    public DoctorHolder(@NonNull View itemView) {
        super(itemView);

        Name = itemView.findViewById(R.id.doctor_name);
        Specialty = itemView.findViewById(R.id.doctor_specialty);
        DocImage = itemView.findViewById(R.id.doctor_image);
    }
}
活动

public class DoctorActivity extends AppCompatActivity {

FirebaseAuth firebaseAuth;
private FirebaseFirestore rootReference = FirebaseFirestore.getInstance();
private CollectionReference doctorRef = rootReference.collection("doctor");

private DoctorAdapter doctorAdapter;


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

    firebaseAuth = FirebaseAuth.getInstance();

    setUpRecyclerView();
}

private void setUpRecyclerView() {

    // Query FireStore and order items by name in Ascending order
    Query query = doctorRef.orderBy("name", Query.Direction.ASCENDING);

    FirestoreRecyclerOptions<Doctor> options = new FirestoreRecyclerOptions.Builder<Doctor>()
            .setQuery(query, Doctor.class)
            .build();

    doctorAdapter = new DoctorAdapter(options);

    RecyclerView recyclerView = findViewById(R.id.doctor_recycler_view);
    recyclerView.setHasFixedSize(true);  // For performance reasons
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setAdapter(doctorAdapter);

}

@Override
protected void onStart() {
    super.onStart();
    doctorAdapter.startListening();
}

@Override
protected void onStop() {
    super.onStop();
    doctorAdapter.stopListening();
}
}

结果是:


代码中的问题在于,在博士类中,getter的名称是错误的。您已定义了以下字段:

private String name;
private String specialty;
使用相应的getter:

public String getmDoctorName() {
    return name;
}

public String getmDoctorSpecialty() {
    return specialty;
}
这是不正确的。获取者的名称应与字段的名称完全相同。请参阅正确的命名:

public String getName() {
    return name;
}

public String getrSpecialty() {
    return specialty;
}
关于最后一项:

private String DoctorImageURL;
数据库中没有任何值。除此之外,您的财产以大写字母开头,这可能导致其他一些问题,如:


请将您的数据库结构添加为屏幕截图。@Alex Mamo我已经添加了数据库结构的图片