简体   繁体   中英

Android Firebase Database exception: not define a no-argument constructor

I'm receiving an error presented below:

com.google.firebase.database.DatabaseException: Class com.example.admin.albumsviewer.Album$Info does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped.

In fact in my model class I have declared no-argument constructors:

package com.example.admin.albumsviewer;

import java.util.ArrayList;
import java.util.List;

public class Album {
    String nazwa;
    String wykonawca;
    String okladkaAlbumu;
    String logoZespolu;
    Info info;
    Utwory utwory;

    public String getNazwa() {
        return nazwa;
    }

    public void setNazwa(String nazwa) {
        this.nazwa = nazwa;
    }

    public String getWykonawca() {
        return wykonawca;
    }

    public void setWykonawca(String wykonawca) {
        this.wykonawca = wykonawca;
    }

    public String getOkladkaAlbumu() {
        return okladkaAlbumu;
    }

    public void setOkladkaAlbumu(String okladkaAlbumu) {
        this.okladkaAlbumu = okladkaAlbumu;
    }

    public String getLogoZespolu() {
        return logoZespolu;
    }

    public void setLogoZespolu(String logoZespolu) {
        this.logoZespolu = logoZespolu;
    }

    public Info getInfo() {
        return info;
    }

    public void setInfo(Info info) {
        this.info = info;
    }

    public Utwory getUtwory() {
        return utwory;
    }

    public void setUtwory(Utwory utwory) {
        this.utwory = utwory;
    }

    public Album(){

    }

    public Album(String nazwa, String wykonawca, String okladkaAlbumu, String logoZespolu, Info info, Utwory utwory) {
        this.nazwa = nazwa;
        this.wykonawca = wykonawca;
        this.okladkaAlbumu = okladkaAlbumu;
        this.logoZespolu = logoZespolu;
        this.info = info;
        this.utwory = utwory;
    }

    public class Info {
        String gatunek;
        int cena;
        int rokWydania;

        public String getGatunek() {
            return gatunek;
        }

        public void setGatunek(String gatunek) {
            this.gatunek = gatunek;
        }

        public int getCena() {
            return cena;
        }

        public void setCena(int cena) {
            this.cena = cena;
        }

        public int getRokWydania() {
            return rokWydania;
        }

        public void setRokWydania(int rokWydania) {
            this.rokWydania = rokWydania;
        }

        public Info() {
        }

        public Info(String gatunek, int cena, int rokWydania) {
            this.gatunek = gatunek;
            this.cena = cena;
            this.rokWydania = rokWydania;
        }
    }

    public class Utwory {
        List<String> utwory;

        public List<String> getUtwory() {
            return utwory;
        }

        public void setUtwory(List<String> utwory) {
            this.utwory = utwory;
        }

        public Utwory(){
        }

        public Utwory(List<String> utwory) {
            this.utwory = utwory;
        }
    }
}

I'am quite confused how to fix that issue. Thanks in advance.

Info and Utwory shouldn't be inner classes nested inside Album . Make them independent classes instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM