com.google.android.gms.maps.model.Polygon类未定义无参数构造函数

时间:2019-05-03 15:23:27

标签: android google-cloud-firestore google-maps-android-api-2

我正在开发一个将多边形发送到Firestore,然后稍后重试的应用程序。问题出在标题上。对于多边形,多边形没有空的构造函数。

我尝试查看其他解决方案,但与多边形不匹配我的问题。有些谈论创建自己的无参数构造函数,但没有以我理解的方式对其进行解释。 (必须在reddit上达到ELI5级别)

我尝试过的所有事情似乎都不起作用,而且令人沮丧。将信息上传到Firebase并仅将其拉下来没有问题。

---------------获取集合的代码--------------

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();
            }
        });

    }

---------------------在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());
                                }

------------------多边形信息模型------------------

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;
    }

-----------------错误代码---------------------------- ------

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)

我希望有一个可以在地图上显示的多边形(GoogleMap),但会得到错误代码。

不知道如何在不使用

的情况下在地图上放置多边形

mMap.addPolygon(polygonOptions);


第一篇文章,因此,如果在如何正确发表文章方面也有一些投入,则会很乐意采用一些指针。

0 个答案:

没有答案