I have a simple Main Activity with a GridView and every item has a TextView which I want to fill with one of the contents of every item stored in Firebase database. The problem emerges when I invoke getValue(). The app crashes and I get the following error:
com.google.firebase.database.DatabaseException: No properties to serialize found on class org.json.JSONObject
I am using a custom Adapter I made to parse the data to the GridView. My code is as follows:
public class MainActivity extends AppCompatActivity {
public JSONArray tables = new JSONArray();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView grid = (GridView) findViewById(R.id.table_grid);
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
DatabaseReference databaseReference = firebaseDatabase.getReference("development/store_1/tables");
databaseReference.child("items").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Iterable<DataSnapshot> children = dataSnapshot.getChildren();
for (DataSnapshot child : children) {
JSONObject table = child.getValue(JSONObject.class);
tables.put(table);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
String error = databaseError.getMessage().toString();
Toast.makeText(MainActivity.this, error, Toast.LENGTH_SHORT).show();
}
});
TableAdapter tableAdapter = new TableAdapter(this, tables, 0);
grid.setAdapter(tableAdapter);
}
}