Skip to content

Firebase

Kokoichi edited this page Sep 24, 2021 · 2 revisions

Error

デフォルトコンストラクターが必要ですよー

エラーメッセージ

2021-09-24 13:42:30.683 32691-32691/io.kokoichi.sample.sakamichiapp E/AndroidRuntime: FATAL EXCEPTION: main
    Process: io.kokoichi.sample.sakamichiapp, PID: 32691
    java.lang.RuntimeException: Could not deserialize object. Class io.kokoichi.sample.sakamichiapp.models.MemberPayload does not define a no-argument constructor. If you are using ProGuard, make sure these constructors are not stripped

key の値と、バインドさせる対象の変数の値は一緒にすべし!

下のログを見ると、データ取得自体はできてそうなのに何故かバインドがうまくいってない...?

      }
      fields {
        key: "name_ja"
        value {
          integer_value: 0
          string_value: "\345\262\251\346\234\254 \350\223\256\345\212\240"
        }
      }
      fields {
        key: "birthday"
        value {
          integer_value: 0
          string_value: "2004\345\271\2642\346\234\2102\346\227\245"
        }
      }
      fields {
        key: "img_url"
        value {
          integer_value: 0
          string_value: "https://firebasestorage.googleapis.com/v0/b/my-memory-3b3bd.appspot.com/o/saka%2Fnogizaka%2Fiwamotorenka.jpeg?alt=media"
        }
      }
    }}}}
2021-09-24 13:50:59.943 1547-1547/io.kokoichi.sample.sakamichiapp D/MainActivity: Member name is iwamotorenka:
2021-09-24 13:50:59.943 1547-1547/io.kokoichi.sample.sakamichiapp D/MainActivity: response is MemberPayload(nameEn=null, nameJa=null, birthday=2004年2月2日, height=159cm, imgUrl=null)
2021-09-24 13:50:59.943 1547-1547/io.kokoichi.sample.sakamichiapp D/MainActivity: url is MemberPayload(nameEn=null, nameJa=null, birthday=2004年2月2日, height=159cm, imgUrl=null).imgUrl

!バインドさせるクラスの名前を変更したらうまくいった!以下のように変更

data class MemberPayload (
    @PropertyName("name_en") val name_en: String? = null,
    @PropertyName("name_ja") val name_ja: String? = null,
    @PropertyName("birthday") val birthday: String? = null,
    @PropertyName("height") val height: String? = null,
    @PropertyName("img_url") val img_url: String? = null
)