I tried to store data in firebase database but the following errors occurs:
Process: com.example.zar.shoppinglistplusfirebase, PID: 2379 java.lang.RuntimeException: java.lang.reflect.InvocationTargetException at com.google.android.gms.internal.zzbqi$zza.zzaF(Unknown Source) at com.google.android.gms.internal.zzbqi.zzax(Unknown Source) at com.google.android.gms.internal.zzbqi.zzaw(Unknown Source) at com.google.firebase.database.DatabaseReference.zza(Unknown Source) at com.google.firebase.database.DatabaseReference.setValue(Unknown Source) at com.example.zar.shoppinglistplusfirebase.ui.activeLists.AddListsFragment.addShoppingList(AddListsFragment.java:115) at com.example.zar.shoppinglistplusfirebase.ui.activeLists.AddListsFragment$1.onEditorAction(AddListsFragment.java:74)
Pojo ShoppingList
package com.example.zar.shoppinglistplusfirebase.model;
import com.example.zar.shoppinglistplusfirebase.Utils.Constants;
import com.google.firebase.database.ServerValue;
import java.util.HashMap;
public class ShoppingList {
private String listName;
private String owner;
private HashMap<String, Object> timestampLastChanged;
/**
* Required public constructor
*/
public ShoppingList() {
}
/**
* Use this constructor to create new ShoppingLists.
* Takes shopping list listName and owner. Set's the last
* changed time to what is stored in ServerValue.TIMESTAMP
*
* @param listName
* @param owner
*
*/
public ShoppingList(String listName, String owner,HashMap<String,Object> timampLastChangedObj) {
this.listName = listName;
this.owner = owner;
HashMap<String, Object> timestampLastChangedObj = new HashMap<String, Object>();
timestampLastChangedObj.put(Constants.FIREBASE_PROPERTY_TIMESTAMP, ServerValue.TIMESTAMP);
this.timestampLastChanged = timestampLastChangedObj;
}
public String getListName() {
return listName;
}
public String getOwner() {
return owner;
}
public HashMap<String, Object> getTimestampLastChanged() {
return timestampLastChanged;
}
public long getTimestampLastChangedLong() {
return (long) timestampLastChanged.get(Constants.FIREBASE_PROPERTY_TIMESTAMP);
}
}
Data Writing to firebase
FirebaseDatabase firebaseDatabase=FirebaseDatabase.getInstance();
DatabaseReference databaseReference=firebaseDatabase.getReferenceFromUrl(Constants.FIREBASE_ACTIVE_LIST_URL);
DatabaseReference ref=databaseReference.push();
HashMap<String,Object> timeStampCreated=new HashMap<>();
timeStampCreated.put(Constants.FIREBASE_PROPERTY_TIMESTAMP, ServerValue.TIMESTAMP);
ShoppingList newShoppingList = new ShoppingList(userEnteredName, owner,timeStampCreated);
ref.setValue(newShoppingList);
AddListsFragment.this.getDialog().cancel();