2016-04-27 84 views
0

我用ArrayListFirebase上存儲數據。它存儲爲HashMap,key值從0開始,其值存儲爲字符串。在POJO中檢索firebase hashmap數據

數據庫如下:

enter image description here

我使用POJO,存儲和檢索數據。

POJO定義如下:

@JsonIgnoreProperties(ignoreUnknown = true) 
public class POJO_MemoriesRVDisplay { 
    String mem_name; 
    String mem_place_street_address; 
    HashMap<Object,Object> images; 

    public POJO_MemoriesRVDisplay() { 
    } 

    public HashMap<Object, Object> getImages() { 
     return images; 
    } 

    public void setImages(HashMap<Object, Object> images) { 
     this.images = images; 
    } 

    public POJO_MemoriesRVDisplay(String mem_name, String mem_place_street_address, HashMap<Object, Object> images) { 
     this.mem_name = mem_name; 
     this.mem_place_street_address = mem_place_street_address; 
     this.images = images; 
    } 

    public String getMem_name() { 
     return mem_name; 
    } 

    public void setMem_name(String mem_name) { 
     this.mem_name = mem_name; 
    } 

    public String getMem_place_street_address() { 
     return mem_place_street_address; 
    } 

    public void setMem_place_street_address(String mem_place_street_address) { 
     this.mem_place_street_address = mem_place_street_address; 
    } 
} 

當我運行這段代碼,我得到一個錯誤,如:

Failed to bounce to type 

如何正確申報POJO。我嘗試了幾個帖子,但無法幫助它。試圖改變圖像的聲明到字符串,仍然無法正常工作。請幫忙!

+0

您已經在您的問題中包含指向JSON樹圖片的鏈接。請將實際的JSON替換爲文本,您可以通過點擊Firebase數據庫中的導出按鈕輕鬆獲取該文本。將JSON作爲文本可以搜索,使我們能夠輕鬆使用它來測試您的實際數據,並將其用於我們的答案中,並且通常只是一件好事。 –

+0

「無法彈出鍵入」有一個「引起」子句,它會告訴您問題的原因。 –

回答

0

嘗試這種解決方案:

//First create your object  
POJO_MemoriesRVDisplay pojo = new POJO_MemoriesRVDisplay("School", "12345", Your hashmap); 

//Create your reference where you want to store your data  
private DatabaseReference root = FirebaseDatabase.getInstance().getReference(); 

//Save your data 
root.push().setValue(pojo); 
1

問題是HashMap的宣言英寸最初聲明爲

Hasmap<Object, Object> images; 

在POJO沒有工作,但試驗和錯誤小時後我刪除了POJO,並重新啓動系統。當我重新創建POJO文件時,我將Hashmap聲明爲:

Hashmap images;