Нет сеттер / поля для полей в моем Android Model_class. при попытке отобразить данные в recyclerView - PullRequest
0 голосов
/ 04 ноября 2018

Вот ссылка на аналогичный пост. Этот пост использует Firebase, а не firestore. Firebase, classmaper: не найдено установщика / поля для 'UserTwo' в классе 'myclass'

Мой адаптер отличается, и я изо всех сил пытаюсь применить логику к моему проекту. У меня есть сеттеры, но они не используются, и я не уверен, где их использовать.

Если я не задал вопрос правильно, я удалю его, у меня просто недостаточно представителя, чтобы задавать вопросы по другим связанным постам.

Ошибка - но на самом деле это не ошибка, это не приводит к сбою моего приложения, в окне рециркулятора ничего не отображается

W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for 
Destination found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for 
Destination found on class com.example.carme.navigation.model_class
         (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for 
Destination found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for 
Destination found on class com.example.carme.navigation.model_class
         (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for 
Destination found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class
         (0.6.6-dev) [CustomClassMapper]: No setter/field for Destination 
found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for 
Destination found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for 
Destination found on class com.example.carme.navigation.model_class
         (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for 
Destination found on class com.example.carme.navigation.model_class
         (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for 
Destination found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for 
Destination found on class com.example.carme.navigation.model_class
          (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for 
Destination found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for 
Destination found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for 
Destination found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class
W/Firestore: (0.6.6-dev) [CustomClassMapper]: No setter/field for 
Destination found on class com.example.carme.navigation.model_class
         (0.6.6-dev) [CustomClassMapper]: No setter/field for Start 
Location found on class com.example.carme.navigation.model_class

Вот мои занятия.

Модель_класса:

package com.example.carme.navigation;

public class model_class {

String Destination;
String StartLocation;

public model_class() {

}

public model_class(String startLocation, String destination) {
    StartLocation = startLocation;
    Destination = destination;
}

public String getDestination() {
    return Destination;
}

public void setDestination(String destination) {
    Destination = destination;
}


public String getStartLocation() {
    return StartLocation;
}

public void setStartLocation(String startLocation) {
    StartLocation = startLocation;
}

}

Мой адаптер класса

package com.example.carme.navigation;

import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

import static android.view.LayoutInflater.from;

public class trips_adapter extends 
RecyclerView.Adapter<trips_adapter.ViewHolder> {

public List<model_class> trips_taken;


public trips_adapter(List<model_class> trips_taken ){
    this.trips_taken = trips_taken;
}

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

    View v = from(parent.getContext()).inflate(R.layout.list_item,parent,false);


    return  new ViewHolder(v);
}

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
    holder.sLocation.setText(trips_taken.get(position).getStart_location());
    holder.eLocation.setText(trips_taken.get(position).getEnd_location());
}

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

public class ViewHolder extends RecyclerView.ViewHolder{

    View v;
    public TextView sLocation;
    public TextView eLocation;



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

        sLocation = v.findViewById(R.id.start_locationTV);
        eLocation = v.findViewById(R.id.end_LocationTV);
    }
}

}

My onCreate, где я звоню в Firestore

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_trips_list);

    FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
    FirebaseFirestore db = FirebaseFirestore.getInstance();
    DocumentReference dbRef = db.collection("users").document(user.getUid());

    trips_taken = new ArrayList<>();
    trips_adapter = new trips_adapter(trips_taken);
    firestore_list = findViewById(R.id.list);
    firestore_list.setHasFixedSize(true);
    firestore_list.setLayoutManager(new LinearLayoutManager(this));
    firestore_list.setAdapter(trips_adapter);


    dbRef.collection("Trips").addSnapshotListener(new EventListener<QuerySnapshot>() {
        public static final String TAG ="" ;

        @Override
        public void onEvent(@Nullable QuerySnapshot queryDocumentSnapshots, @Nullable FirebaseFirestoreException e) {
            if(e!=null){
                Log.d(TAG,"Error"+e.getLocalizedMessage());
            }

            for(DocumentChange documentChange : queryDocumentSnapshots.getDocumentChanges()){
                if(documentChange.getType() == DocumentChange.Type.ADDED){
                    String trips = (String) documentChange.getDocument().get("Trips");

                    model_class MC = documentChange.getDocument().toObject(model_class.class);
                    trips_taken.add(MC);
                    trips_adapter.notifyDataSetChanged();
                }
            }
        }
    });

После исправления моих полей НОВАЯ ОШИБКА - исправить ниже

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.example.carme.navigation, PID: 19915
                  java.lang.RuntimeException: Found two getters or fields with conflicting case sensitivity for property: destination
                      at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.addProperty(com.google.firebase:firebase-firestore@@17.1.2:669)
                      at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.<init>(com.google.firebase:firebase-firestore@@17.1.2:585)
                      at com.google.firebase.firestore.util.CustomClassMapper.loadOrCreateBeanMapperForClass(com.google.firebase:firebase-firestore@@17.1.2:347)
                      at com.google.firebase.firestore.util.CustomClassMapper.convertBean(com.google.firebase:firebase-firestore@@17.1.2:501)
                      at com.google.firebase.firestore.util.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-firestore@@17.1.2:242)
                      at com.google.firebase.firestore.util.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-firestore@@17.1.2:97)
                      at com.google.firebase.firestore.DocumentSnapshot.toObject(com.google.firebase:firebase-firestore@@17.1.2:203)
                      at com.google.firebase.firestore.QueryDocumentSnapshot.toObject(com.google.firebase:firebase-firestore@@17.1.2:121)
                      at com.google.firebase.firestore.DocumentSnapshot.toObject(com.google.firebase:firebase-firestore@@17.1.2:183)
                      at com.google.firebase.firestore.QueryDocumentSnapshot.toObject(com.google.firebase:firebase-firestore@@17.1.2:101)
                      at com.example.carme.navigation.trips_list$1.onEvent(trips_list.java:65)
                      at com.example.carme.navigation.trips_list$1.onEvent(trips_list.java:52)
                      at com.google.firebase.firestore.Query.lambda$addSnapshotListenerInternal$2(com.google.firebase:firebase-firestore@@17.1.2:882)
                      at com.google.firebase.firestore.Query$$Lambda$3.onEvent(Unknown Source:6)
                      at com.google.firebase.firestore.util.ExecutorEventListener.lambda$onEvent$0(com.google.firebase:firebase-firestore@@17.1.2:42)
                      at com.google.firebase.firestore.util.ExecutorEventListener$$Lambda$1.run(Unknown Source:6)
                      at android.os.Handler.handleCallback(Handler.java:789)
                      at android.os.Handler.dispatchMessage(Handler.java:98)
                      at android.os.Looper.loop(Looper.java:164)
                      at android.app.ActivityThread.main(ActivityThread.java:6938)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:327)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1374)
I/OpenGLRenderer: prepareTree mLayerUpdateQueue is not empty, size = 1
I/OpenGLRenderer: name = PopupWindow$PopupBackgroundView, size (515, 504)
Application terminated.

Я исправил это, изменив имя моих геттеров и сеттеров

от

 public void setDestination(String destination) {

до

 public String getDestinationTrip() {
    return Destination;
}

База данных

Сохранение общей информации пользователя

public void saveData(View view) {
        FirebaseUser users = FirebaseAuth.getInstance().getCurrentUser();
        db = FirebaseFirestore.getInstance();

        Map<String, Object> user = new HashMap<>();
        user.put("Name", user_name.getText().toString());
        user.put("Surname", user_surname.getText().toString());
        if (driving.isChecked()) {
            user.put("Mode of Transport", "Driving");
        } else if (walking.isChecked()) {
            user.put("Mode of Transport", "Walking");
        } else if (cycling.isChecked()) {
            user.put("Mode of Transport", "Cycling");
        }

        user.put("Home Address", user_home_address.getText().toString());

        db.collection("users").document(users.getUid()).set(user);

        startActivity(new Intent(preferences.this, profilePage.class));

предпринятые спасательные поездки

public void saveAddresses() {
        Map<String,Object> Trips = new HashMap<>();
        Trips.put("Start Location",setLocation.getText().toString());
        Trips.put("Destination",setDestination.getText().toString());


        dbRef.collection("Trips").add(Trips);
        dbRef.collection("Start Location").document("Start Location").update("Trips",FieldValue.arrayUnion(setLocation.getText().toString()));
        dbRef.collection("Destination").document("Destination").update("Trips",FieldValue.arrayUnion(setDestination.getText().toString()));
        dbRef.update("Trips",FieldValue.arrayUnion(Trips));

    }

Просмотр Firestore с данными

1 Ответ

0 голосов
/ 04 ноября 2018

Ваши поля, вероятно, не совпадают, поэтому, пожалуйста, попробуйте обновить поля , getters и setters в вашем model_class:

public class model_class {

    String StartLocation;
    String Destination;

    // Update your getters and setters...

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