How to declare a constructor without arguments?

1

I'm trying to get all the documents from firebase and convert them directly into an object but I jump with the following error:

  

java.lang.RuntimeException: Could not deserialize object. Class com.chdzma.changeproject.objects.Food does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped

And this is the class:

class Food(name:String, description: String, calories: Int, carbo: Int, fats: Int, proteins: Int, sodium: Int, sugar: Int) : Item{

    val name = name
    val description = description
    val calories = calories
    val carbo = carbo
    val fats = fats
    val proteins = proteins
    val sodium = sodium
    val sugar = sugar

    override fun getViewType(): Int {
        return 1
    }

}
    
asked by chdzma 20.05.2018 в 22:27
source

1 answer

1

only defines an empty constructor, this is necessary to capture data from firebase

class Food(){

 }

class Food(name:String, description: String, calories: Int, carbo: Int, fats: Int, proteins: Int, sodium: Int, sugar: Int) : Item{

    val name = name
    val description = description
    val calories = calories
    val carbo = carbo
    val fats = fats
    val proteins = proteins
    val sodium = sodium
    val sugar = sugar

    override fun getViewType(): Int {
        return 1
    }
    
answered by 15.07.2018 / 01:46
source