W / ClassMapper:" class"没有setter / field在android上的类中找到

时间:2017-03-22 09:27:21

标签: android listview firebase firebase-realtime-database

我正在尝试从firebase数据库中检索数据并在listview上显示它们。我的应用程序在低于7.0的Android版本上工作正常,而在版本7.0中,listview中没有显示任何内容。这就是我在日志中获得的内容:

W/ClassMapper: No setter/field for ExpenseTag found on class com.example.siddhi.ExpenseManager.Data.Expense

这里BarActivity.class:

BarAdapter m_adapter = new BarAdapter(ListBarActivity.this, R.layout.bar_layout, tagsArrayList);

            // display the list.
            listView.setAdapter(m_adapter);

这里有Expense.class

package com.example.siddhi.ExpenseManager.Data;


public class Expense {
          public String expenseId;
          public String expenseName;


    public Expense() {
         /*Blank default constructor essential for Firebase*/
    }

    public Expense( String expenseId, String expenseName, ) {

                           this.expenseName = expenseName;
                                this.expenseId = expenseId;

               }


    //Getters and setters
    public void setExpenseName(String expenseName) {
        this.expenseName = expenseName;
    }


    public void setExpenseId(String expenseId) {
        this.expenseId = expenseId;
    }

       public String getExpenseName() {
        return expenseName;
    }


    public String getExpenseId() {
        return expenseId;
    }


    @Exclude
    public Map<String, Object> toMap() {
        HashMap<String, Object> result = new HashMap<>();
       result.put("expenseName", expenseName);
       result.put("expenseId", expenseId);
        return result;
    }
}

这里有其他的EXpenseTag.Class:

 package com.example.siddhi.ExpenseManager.Data;



public class ExpenseTag {

    public String tagId;
    public String tagName;


    public ExpenseTag() {

         /*Blank default constructor essential for FireBase*/
    }


    public ExpenseTag( String tagId, String tagName) {
        this.tagId = tagId;
        this.tagName = tagName;

    }
    //Getters and setters
    public void setTagId(String tagId) {
        this.tagId = tagId;
    }

    public void setTagName(String tagName) {
        this.tagName = tagName;
    }
    public String getTagId() {
        return tagId;
    }
    public String getTagName() {
        return tagName;
    }

    @Exclude
    public Map<String, Object> toMap() {
        HashMap<String, Object> result = new HashMap<>();
        result.put("tagId", tagId);
        result.put("tagName", tagName);
        return result;
    }
}

用于获取数据:

  final Query BarQuery = databaseReference11.child("Users").child("Expense");


    BarQuery.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot tagsSnapshot : dataSnapshot.getChildren()) {
                Expense expense = tagsSnapshot.getValue(Expense.class);
                tagsArrayList.add(expense);

            }
        }//}

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.e("deeep", "onCancelled", databaseError.toException());
        }
    });

Json数据:

 "ExpenseList" : {
        "-Ke8TQJeVar6nMlzEkbI" : {
          "Expense" : {
            "-KftUp3S5TvZuSbB30CW" : {
              "ExpenseTag" : {
                "-KftUp3Eyjf3cZZncvvT" : {
                  "tagId" : "-KftUp3Eyjf3cZZncvvT",
                  "tagName" : "tag"
                }
              },
             "expenseId" : "-KftUp3S5TvZuSbB30CW",
             "expenseName" : "bb",
                             }
          },
          "expenseListName" : "Dfg",

        }

1 个答案:

答案 0 :(得分:1)

问题是您已经创建了ExpenseTag模型,但没有将其作为字段添加到Expense模型中。 我已经为您更新了费用模型。

 public class Expense {

    public ExpenseTag expenseTag;
    public String expenseId;
    public String expenseName;

    public Expense() {
         /*Blank default constructor essential for Firebase*/
    }

    public Expense(ExpenseTag expenseTag , String expenseId, String expenseName) {

        this.expenseTag = expenseTag;
        this.expenseName = expenseName;
        this.expenseId = expenseId;

    }

    public ExpenseTag getExpenseTag() {
        return expenseTag;
    }

    public void setExpenseTag(ExpenseTag expenseTag) {
        this.expenseTag = expenseTag;
    }

    //Getters and setters
    public void setExpenseName(String expenseName) {
        this.expenseName = expenseName;
    }


    public void setExpenseId(String expenseId) {
        this.expenseId = expenseId;
    }

    public String getExpenseName() {
        return expenseName;
    }


    public String getExpenseId() {
        return expenseId;
    }


    @Exclude
    public Map<String, Object> toMap() {
        HashMap<String, Object> result = new HashMap<>();
        result.put("expenseName", expenseName);
        result.put("expenseId", expenseId);
        return result;
    }
}