0

I used an ArrayList to store data on Firebase.It got stored as a HashMap with key value starting from 0 and its value stored as string.

The database is as follows:

enter image description here

I am using POJO, to store and retrieve data.

My POJO is defined as follow:

@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;
    }
}

When I run this code, I get an error such as:

Failed to bounce to type

How do I declare the POJO properly. I have tried several posts but couldn't help it. Tried changing the declaration of images to strings, still wouldn't work. Please help!

V-rund Puro-hit
  • 5,518
  • 9
  • 31
  • 50
  • You've included a link to a picture of the JSON tree in your question. Please replace that with the actual JSON as text, which you can easily get by clicking the Export button in your Firebase database. Having the JSON as text makes it searchable, allows us to easily use it to test with your actual data and use it in our answer and in general is just a Good Thing to do. – Frank van Puffelen Apr 27 '16 at 14:25
  • The "Failed to bounce to type" has a "caused by" clause that will tell you the cause of the problem. – Frank van Puffelen Apr 27 '16 at 14:27

2 Answers2

1

The problem was in the Hashmap Declaration. Initially declaring it as

Hasmap<Object, Object> images;

didn't work in the POJO but after hours of trial and error I deleted the POJO and restarted the system. When I recreated the POJO file, I declared the Hashmap as:

Hashmap images;
0

Try with this solution:

//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); 
Matteo Baldi
  • 5,613
  • 10
  • 39
  • 51
Ayoub
  • 1
  • 2