将Firebase与RecyclearView

时间:2018-01-07 15:32:39

标签: java android firebase firebase-realtime-database

我在运行我的应用时遇到了这些错误:

  

致命例外:主要流程:com.google.example.adinaranayaragh,PID:26564                                                                                           com.google.firebase.database.DatabaseException:类com.google.example.adinaranayaragh.MyItem $ Sellm未定义无参数构造函数。如果您使用的是ProGuard,请确保不剥离这些构造函数。                                                                                               在com.google.android.gms.internal.zzelx.zze(未知来源)                                                                                               在com.google.android.gms.internal.zzelw.zzb(未知来源)                                                                                               在com.google.android.gms.internal.zzelw.zza(未知来源)                                                                                               在com.google.android.gms.internal.zzelw.zzb(未知来源)                                                                                               在com.google.android.gms.internal.zzelx.zze(未知来源)                                                                                               在com.google.android.gms.internal.zzelw.zzb(未知来源)                                                                                               在com.google.android.gms.internal.zzelw.zza(未知来源)                                                                                               在com.google.firebase.database.DataSnapshot.getValue(未知来源)                                                                                               在com.google.example.adinaranayaragh.FirebaseRecyclerAdapter.getConvertedObject(FirebaseRecyclerAdapter.java:301)                                                                                               在com.google.example.adinaranayaragh.FirebaseRecyclerAdapter $ 1.onChildAdded(FirebaseRecyclerAdapter.java:80)                                                                                               在com.google.android.gms.internal.zzecw.zza(未知来源)                                                                                               在com.google.android.gms.internal.zzeia.zzbyc(未知来源)                                                                                               在com.google.android.gms.internal.zzeig.run(未知来源)                                                                                               在android.os.Handler.handleCallback(Handler.java:815)                                                                                               在android.os.Handler.dispatchMessage(Handler.java:104)                                                                                               在android.os.Looper.loop(Looper.java:207)                                                                                               在android.app.ActivityThread.main(ActivityThread.java:5728)                                                                                               at java.lang.reflect.Method.invoke(Native Method)                                                                                               在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:789)                                                                                               在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

我的项目可用on Github

这是firebase数据库结构:

{
    "items": {
        "it1": {
            "buy": {
                "buyBellow": 19023,
                "date": "7.jan2016",
                "stoploss": 12455,
                "target1": 12548,
                "target2": 12444
            },
            "sell": {
                "date": "7jan",
                "sellAbove": 22000,
                "stoploss": 14522,
                "target1": 21222,
                "target2": 22245
            },
            "title": "Gold"
        },
        "it2": {
            "buy": {
                "buyBellow": 19023,
                "date": "7.jan2016",
                "stoploss": 12455,
                "target1": 12548,
                "target2": 12444
            },
            "sell": {
                "date": "7jan",
                "sellAbove": 22000,
                "stoploss": 14522,
                "target1": 21222,
                "target2": 22245
            },
            "title": "GoldM"
        },
        "it3": {
            "buy": {
                "buyBellow": 19023,
                "date": "7.jan2016",
                "stoploss": 12455,
                "target1": 12548,
                "target2": 12444
            },
            "sell": {
                "date": "7jan",
                "sellAbove": 22000,
                "stoploss": 14522,
                "target1": 21222,
                "target2": 22245
            },
            "title": "Silver"
        },
        "it4": {
            "buy": {
                "buyBellow": 19023,
                "date": "7.jan2016",
                "stoploss": 12455,
                "target1": 12548,
                "target2": 12444
            },
            "sell": {
                "date": "7jan",
                "sellAbove": 22000,
                "stoploss": 14522,
                "target1": 21222,
                "target2": 22245
            },
            "title": "SilverM"
        }
    },
    "news": ""
}

我想要完成的是让RecyclerView中的这些对象(项目)出现在我的应用中,但是当我尝试运行它时会出现上述错误。

1 个答案:

答案 0 :(得分:0)

您应该将Sellm设为静态或在单独的文件中声明它。

public class MyItem {
    ....

    public static class Sellm {
        ....
    }
}