I'm working on an application that sends a polygon to firestore, and then retries it later. The problem is at it's written in the title. Polygon doesn't have a empty constructor, for the polygon.
I have tried to look at other solutions, but non fitting my problem, with the polygons. Some talks about creating ones own no-argument constructor, but not explaining it in a way that I understand. (Have to be almost at the ELI5 level on reddit)
Non of the things that I have tried, seemed to work, and its frustrating. There is no problem with uploading the information to firebase, only pulling it down.
---------------The code for fetching the collection --------------
private void getFlightZonesRef(){
CollectionReference mFlightZonesRef = mDb
.collection(getString(R.string.collection_flight_zones));
mFlightZonesRef.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
if(task.isSuccessful()){
for (QueryDocumentSnapshot fZ : task.getResult()){
Log.d(TAG, "onComplete: TESTING: " + fZ.getData());
flyZonesModel = fZ.toObject(FlyZonesModel.class);
Log.d(TAG, "onComplete: REFFlyZone: " + flyZonesModel.toString());
}
}else Toast.makeText(getContext(), "Something went wrong \n getting data from FireBase", Toast.LENGTH_SHORT).show();
}
});
}
---------------------Saving the information on firebase -----------
DocumentReference newPolygonRef = mDb
.collection(getString(R.string.collection_flight_zones))
.document();
newPolygonRef.set(flyZonesModel).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
if (task.isSuccessful()){
Toast.makeText(getContext(), "Zone, succesfully added to database", Toast.LENGTH_SHORT).show();
mNameOfArea.setText("");
mDescriptionOfArea.setText("");
if (polygon != null){
polygon.remove();
polygon = null;
}
}else{
Toast.makeText(getContext(), "Something went wrong", Toast.LENGTH_SHORT).show();
Log.d(TAG, "onComplete: Faliure:" + task.getException());
}
------------------polygon information model ------------------
package com.bach.droneinfo.models;
import android.os.Parcel;
import android.os.Parcelable;
import com.google.android.gms.maps.model.Polygon;
public class FlyZonesModel implements Parcelable {
private String name;
private String description;
private Polygon zone;
public FlyZonesModel(Polygon zone, String name, String description) {
this.name = name;
this.description = description;
this.zone = zone;
}
public FlyZonesModel() {
}
¨¨¨¨¨
more code
¨¨¨¨¨
public Polygon getZone() {
return zone;
}
public void setZone(Polygon zone) {
this.zone = zone;
}
----------------- ERROR CODE ----------------------------------
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.bach.droneinfo, PID: 11682
java.lang.RuntimeException: Could not deserialize object. Class com.google.android.gms.maps.model.Polygon does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped (found in field 'zone')
at com.google.firebase.firestore.util.CustomClassMapper.deserializeError(com.google.firebase:firebase-firestore@@18.2.0:539)
at com.google.firebase.firestore.util.CustomClassMapper.access$200(com.google.firebase:firebase-firestore@@18.2.0:53)
at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-firestore@@18.2.0:695)
at com.google.firebase.firestore.util.CustomClassMapper$BeanMapper.deserialize(com.google.firebase:firebase-firestore@@18.2.0:689)
at com.google.firebase.firestore.util.CustomClassMapper.convertBean(com.google.firebase:firebase-firestore@@18.2.0:518)
at com.google.firebase.firestore.util.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-firestore@@18.2.0:248)
at com.google.firebase.firestore.util.CustomClassMapper.deserializeToType(com.google.firebase:firebase-firestore@@18.2.0:186)
I wanted to have a polygon that could de displayed on the map (GoogleMap) but get the error code instead.
have no idea on how to place a polygon on the map without using
mMap.addPolygon(polygonOptions);
First post, so if there is also some input on how to post correctly, some pointers would be gladly taken.