3

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.

1 Answer 1

5

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

Sign up to request clarification or add additional context in comments.

4 Comments

Check your in for class.
I think it works, but I received another error: com.google.firebase.database.DatabaseException: Can't convert object of type java.util.ArrayList to type com.example.admin.albumsviewer.Utwory. I tried to change type of field "utwory" in my "Utwory" class for ArrayList<String> and normal array but it's giving me all the time this same error. How can I fix that issue?
Since this is a different problem, tou should probably ask a different question, but this time show exactly the data you're trying to read.
As an alternative to making Info and Utwory their own top-level classes, you can keep them as inner classes and mark them static, so static public class Info { ....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.