Java 将对象推送到Firebase实时数据库时出现StackOverflower错误

Java 将对象推送到Firebase实时数据库时出现StackOverflower错误,java,android,firebase,firebase-realtime-database,Java,Android,Firebase,Firebase Realtime Database,Firebase实时数据库在我尝试推送BankAccount对象时崩溃java.lang.StackOverflower错误:堆栈大小8MB。我已经用Strings替换了所有对象变量,并排除了getSubcategoryByName方法,但这些都没有帮助 private long amount; private String description; private String subcategoryName, primaryCategoryName; private long creatio

Firebase实时数据库在我尝试推送
BankAccount
对象时崩溃
java.lang.StackOverflower错误:堆栈大小8MB
。我已经用
Strings
替换了所有对象变量,并排除了
getSubcategoryByName
方法,但这些都没有帮助

private long amount;
private String description;
private String subcategoryName, primaryCategoryName;
private long creationDate;
private int type;

private boolean autoPayBill;

public Bill(){ }

public Bill(long amount, String description, String subcategoryName, String primaryCategoryName, int type, boolean autoPayBill, long creationDate) {
    this.amount = amount;
    this.description = description;
    this.subcategoryName = subcategoryName;
    this.primaryCategoryName = primaryCategoryName;
    this.creationDate = creationDate;
    this.autoPayBill = autoPayBill;
    this.type = type;
}

public Bill(long amount, String description, int type, boolean autoPayBill, String subcategoryName, String primaryCategoryName) {
    this.amount = amount;
    this.description = description;
    this.subcategoryName = subcategoryName;
    this.primaryCategoryName = primaryCategoryName;
    this.type = type;
    this.autoPayBill = autoPayBill;
    creationDate = System.currentTimeMillis();
}

public long getAmount() {
    return amount;
}

public void setAmount(long amount) {
    this.amount = amount;
}

public boolean isAutoPayBill() {
    return autoPayBill;
}

public void setAutoPayBill(boolean autoPayBill) {
    this.autoPayBill = autoPayBill;
}

public String getDescription() {
    return description;
}

public void setDescription(String descriptions) {
    this.description = descriptions;
}

public Subcategory getSubcategory() {
    return getSubcategoryByName();
}

public void setSubcategory(Subcategory subcategory) {
    this.subcategoryName = subcategory.getName();
}

public String getSubcategoryName() {
    return subcategoryName;
}

public void setSubcategoryName(String subcategoryName) {
    this.subcategoryName = subcategoryName;
}

public String getPrimaryCategoryName() {
    return primaryCategoryName;
}

public void setPrimaryCategoryName(String primaryCategoryName) {
    this.primaryCategoryName = primaryCategoryName;
}

public long getCreationDate() {
    return creationDate;
}

public void setCreationDate(long creationDate) {
    this.creationDate = creationDate;
}

public int getType() {
    return type;
}

public void setType(int type) {
    this.type = type;
}

@Exclude
private Subcategory getSubcategoryByName(){
    for (PrimaryCategory primaryCategory:Database.getPrimaryCategories()){
        if (primaryCategory.getName().equals(primaryCategoryName)){
            for (Subcategory subcategory:primaryCategory.getSubcategories()){
                if (subcategory.getName().equals(subcategoryName)){
                    return subcategory;
                }
            }
        }
    }

    throw new IllegalArgumentException("Couldn't find subcategory by name!");
}
}

这是
BankAccount
类,它有一个
ArrayList
变量,该变量保存所有
票据

公营银行帐户{

private String name;

private long balance; //In cents

private ArrayList<Bill> bills;

private boolean primaryAccount;

private long creationDate;

private ArrayList<BalanceChange> balanceChanges;

public BankAccount(){

}

public BankAccount(String name, long balance, boolean primaryAccount, long creationDate) {
    this.name = name;
    this.balance = balance;
    this.primaryAccount = primaryAccount;
    this.creationDate = creationDate;
    bills = new ArrayList<>();
    balanceChanges = new ArrayList<>();
}

public BankAccount(String name, long balance, boolean primaryAccount) {
    this.name = name;
    this.balance = balance;
    this.primaryAccount = primaryAccount;
    creationDate = System.currentTimeMillis();
    bills = new ArrayList<>();
    balanceChanges = new ArrayList<>();
}

public String getName() {
    return name;
}

public void addBill(Bill bill) {
    if (bill.getType() == Bill.TYPE_INPUT){
        setBalance(getBalance() + bill.getAmount());
} else if(bill.getType() == Bill.TYPE_OUTPUT){
        setBalance(getBalance() - bill.getAmount());
    }

    bills.add(bill);
    balanceChanges.add(new BalanceChange(System.currentTimeMillis(), this.getBalance()));

}

public void setName(String name) {
    this.name = name;
}

public long getBalance() {
    return balance;
}

public void setBalance(long balance) {
    this.balance = balance;
}

public ArrayList<Bill> getBills() {
    return bills;
}

public void setBills(ArrayList<Bill> bills) {
    this.bills = bills;
}

public boolean isPrimaryAccount() {
    return primaryAccount;
}

public void setPrimaryAccount(boolean primaryAccount) {
    this.primaryAccount = primaryAccount;
}

public long getCreationDate() {
    return creationDate;
}

public void setCreationDate(long creationDate) {
    this.creationDate = creationDate;
}

public ArrayList<BalanceChange> getBalanceChanges() {
    return balanceChanges;
}

public void setBalanceChanges(ArrayList<BalanceChange> balanceChanges) {
    this.balanceChanges = balanceChanges;
}
私有字符串名称;
私人长期余额;//以美分为单位
私人ArrayList法案;
私人布尔主帐户;
私人长时间创作;
私人ArrayList余额变化;
公共银行账户(){
}
公共银行帐户(字符串名称、长余额、布尔主帐户、长创建日期){
this.name=名称;
这个平衡=平衡;
this.primarycount=primarycount;
this.creationDate=creationDate;
bills=新的ArrayList();
balanceChanges=新的ArrayList();
}
公共银行帐户(字符串名称、长余额、布尔主帐户){
this.name=名称;
这个平衡=平衡;
this.primarycount=primarycount;
creationDate=System.currentTimeMillis();
bills=新的ArrayList();
balanceChanges=新的ArrayList();
}
公共字符串getName(){
返回名称;
}
公共票据(票据){
if(bill.getType()==bill.TYPE\u输入){
setBalance(getBalance()+bill.getAmount());
}else if(bill.getType()==bill.TYPE\u输出){
setBalance(getBalance()-bill.getAmount());
}
法案。添加(法案);
balanceChanges.add(新的BalanceChange(System.currentTimeMillis(),this.getBalance());
}
公共void集合名(字符串名){
this.name=名称;
}
公共长期资产负债表(){
收益余额;
}
公共余额(长期余额){
这个平衡=平衡;
}
公共阵列列表getBills(){
退票;
}
公共无效退票(ArrayList票据){
这个。账单=账单;
}
公共布尔值isPrimaryAccount(){
返回主帐户;
}
公共无效setPrimaryAccount(布尔primaryAccount){
this.primarycount=primarycount;
}
公共长getCreationDate(){
还肌酐;
}
公共无效设置创建日期(长创建日期){
this.creationDate=creationDate;
}
公共阵列列表getBalanceChanges(){
返回平衡变化;
}
公共无效设置余额更改(ArrayList余额更改){
此。平衡变化=平衡变化;
}
}

以及如何将对象推送到Firebase

    public void createServerBackup(ArrayList<BankAccount> bankAccounts){
        DatabaseReference bankAccountsReference = userReference.child(BANK_ACCOUNTS_REFERENCE);
        bankAccountsReference.setValue(bankAccounts);
}
public void createServerBackup(ArrayList银行账户){
DatabaseReference bankAccountsReference=userReference.child(BANK\u ACCOUNTS\u REFERENCE);
bankAccountsReference.setValue(银行账户);
}

我猜你在某处有无限的引用循环。Post
BankAccount
对象和您保存它的方式。@nikis这是我保存它的方式
public void createServerBackup(ArrayList bankAccounts){DatabaseReference bankAccountsReference=userReference.child(BANK_ACCOUNTS_REFERENCE);bankAccountsReference.setValue(bankAccounts);}
请通过添加用于将
银行账户添加到数据库中的代码来编辑您的问题,并请用@回复。@niks我现在编辑了我的问题明显的问题:您试图保存的数据到底有多大?