0
我有一個有Bitmap對象的類,並且當我將FireValue(MyClass.class)設置爲FirebaseDatabase時,我發現這是可能的! RealtimeDatabase保存位圖圖像的屬性。發生此問題時,我讀取值,發生跟隨錯誤:從Android的FirebaseDatabase獲取位圖時出錯Error
com.google.firebase.database.DatabaseException: Class android.graphics.Bitmap is missing a constructor with no arguments
但我不能覆蓋位圖圖像的構造函數。我怎樣才能解決這種情況?
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Iterator<DataSnapshot> iterator = dataSnapshot.getChildren().iterator();
log("Init ValueEventListener onDataChange()");
while(iterator.hasNext()) {
DataSnapshot data = iterator.next();
log("Data : " + data.getKey());
Treino t = data.getValue(Treino.class);
}
}
}
public class Treino implements Serializable{
String nome;
List<Exercicio> listaExercicios;
List<Integer> listaDiasSemana;
String hora; // hh:mm
public Treino(String nome, List<Exercicio> listaExercicios, List<Integer> listaDiasSemana, String hora) {
this.nome = nome;
this.listaExercicios = listaExercicios;
this.listaDiasSemana = listaDiasSemana;
this.hora = hora;
}
public class Exercicio implements Serializable {
String nome, tipo, nomeImagem;
Bitmap imagem;
public Exercicio() {
}
public Exercicio(String nome, Bitmap imagem, String nomeImagem) {
this.nome = nome;
this.imagem = imagem;
this.nomeImagem = nomeImagem;
}
我省略了getters和setters。
是的,它的作品! – Augusto