W / Firestore: [CustomClassMapper]: нет установщика / поля для класса Android - PullRequest
0 голосов
/ 20 сентября 2019

Я пытался загрузить данные из класса Documents с помощью Recyclerview, но ошибка появляется в logcat "W / Firestore: (21.1.1) [CustomClassMapper]: не найден установщик / поле для имени документа в классе id.MuhammadRafi.StockCount.Documents».Кстати, где моя вина?

Моя база данных Firestore

Поле документов

Documents.class:

public class Documents extends DocumentID {
    String documentName;
    String documentDate;
    String inspectorName;
    String marketLocation;

public Documents() {

}

public Documents(String documentName, String documentDate, String inspectorName, String marketLocation) {
    this.documentName = documentName;
    this.documentDate = documentDate;
    this.inspectorName = inspectorName;
    this.marketLocation = marketLocation;
}

public String getDocumentName() {
    return documentName;
}

public String getDocumentDate() {
    return documentDate;
}

public String getInspectorName() {
    return inspectorName;
}

public String getMarketLocation() {
    return marketLocation;
}

public void setDocumentName(String documentName) {
    this.documentName = documentName;
}

public void setDocumentDate(String documentDate) {
    this.documentDate = documentDate;
}

public void setInspectorName(String inspectorName) {
    this.inspectorName = inspectorName;
}

public void setMarketLocation(String marketLocation) {
    this.marketLocation = marketLocation;
}
}

DocumentList.class:

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class DocumentList extends RecyclerView.Adapter<DocumentList.ViewHolder> {
    private List<Documents> documentsList;
    private Context context;

public DocumentList(Context context, List<Documents> documentsList) {
    this.documentsList = documentsList;
    this.context = context;
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.list_document_layout, parent, false);
    return new ViewHolder(view);
}

@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    Documents adapterDocuments = documentsList.get(position);

    holder.textViewDocumentName.setText(adapterDocuments.getDocumentName());
    holder.textViewDate.setText(adapterDocuments.getDocumentDate());
    holder.textViewInspector.setText(adapterDocuments.getInspectorName());
    holder.textViewLocation.setText(adapterDocuments.getMarketLocation());
}

@Override
public int getItemCount() {
    return documentsList.size();
}

public class ViewHolder extends RecyclerView.ViewHolder {

    public TextView textViewDocumentName, textViewLocation, textViewInspector, textViewDate;

    public ViewHolder(View itemView) {
        super(itemView);

        textViewDocumentName = itemView.findViewById(R.id.textNameDocument);
        textViewLocation = itemView.findViewById(R.id.textLocation);
        textViewInspector = itemView.findViewById(R.id.textInspector);
        textViewDate = itemView.findViewById(R.id.textDocumentDate);
    }
}
}

StartCounting.class:

public class StartCounting extends AppCompatActivity {
    private DocumentList documentListAdapter;
    private RecyclerView recyclerViewDocument;
    private RecyclerView.LayoutManager layoutManager;
    private FirebaseFirestore firebaseFirestore;

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_start_counting);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    firebaseFirestore = FirebaseFirestore.getInstance();

    documentsList = new ArrayList<>();
    documentListAdapter = new DocumentList(getApplicationContext(), documentsList);

    recyclerViewDocument = findViewById(R.id.recyclerViewDocument);
    recyclerViewDocument.setHasFixedSize(true);

    layoutManager = new LinearLayoutManager(this);
    recyclerViewDocument.setLayoutManager(layoutManager);

    recyclerViewDocument.setAdapter(documentListAdapter);

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

    firebaseFirestore.collection("Users").document(currentUser.getUid()).collection("Documents").get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if(task.isSuccessful()) {
                for(DocumentSnapshot documentSnapshot : task.getResult()) {
                    Documents documents = documentSnapshot.toObject(Documents.class);
                    documentsList.add(documents);

                    documentListAdapter.notifyDataSetChanged();
                }
            }
        }
    });

Ответы [ 2 ]

1 голос
/ 20 сентября 2019

Проблема в вашем коде заключается в том, что имена полей в вашем классе Documents отличаются от имен свойств в вашей базе данных.В вашем классе Documents четыре поля с именами documentName, documentDate, inspectorName, marketLocation, а в базе данных я вижу, что имена разные, Document Name, Document Date, Inspector Name иMarket Location и это не правильно.Имена должны совпадать.

У вас есть решения.Первый - изменить имя ваших друзей в классе Documents в соответствии с тем, что он уже существует в базе данных, или вы можете использовать аннотацию перед геттерами так:

@PropertyName("Document Name")
public String getDocumentName() {
    return documentName;
}
1 голос
/ 20 сентября 2019

В основном, если вы хотите превратить ваш документ в класс данных, поля вашего класса данных должны называться так же, как поля вашего пожарного депо.Так что если в вашем классе данных у вас есть documentName, в вашем пожарном хранилище должна быть переменная с именем documentName, а не Document Name.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...