我有带实时数据库的Firebase应用程序,我有db.json作为
{
"brs" : {
"route": [
{
"routeDestination": "DDDD1",
"routeOrigin": "OOOO1",
"bus" : {
"busArrivalTime" : "created_at_timestamp",
"busDepartureTime" : "created_at_timestamp",
"busName" : "SOME NAME",
"busSeatCost" : "0000",
"busTotalSeats" : "000",
"reservations": [
{
"reservationId": 1,
"reservationDate": "Wed Jul 06 23:54:56 EDT 2016",
"seats": [
{
"seatNumber": 1
},
{
"seatNumber": 2
}
]
}
]
}
},
{
"routeDestination": "DDDD2",
"routeOrigin": "OOOO2",
"bus" : {
"busArrivalTime" : "created_at_timestamp",
"busDepartureTime" : "created_at_timestamp",
"busName" : "SOME NAME",
"busSeatCost" : "0000",
"busTotalSeats" : "000",
"reservations": [
{
"reservationId": 1,
"reservationDate": "Wed Jul 06 23:54:56 EDT 2016",
"seats": [
{
"seatNumber": 1
},
{
"seatNumber": 2
}
]
}
]
}
},
{
"routeDestination": "DDDD3",
"routeOrigin": "OOOO3",
"bus" : {
"busArrivalTime" : "created_at_timestamp",
"busDepartureTime" : "created_at_timestamp",
"busName" : "SOME NAME",
"busSeatCost" : "0000",
"busTotalSeats" : "000",
"reservations": [
{
"reservationId": 1,
"reservationDate": "Wed Jul 06 23:54:56 EDT 2016",
"seats": [
{
"seatNumber": 1
},
{
"seatNumber": 2
}
]
}
]
}
}
]
}
}
现在在android应用程序中,我想检索列表中的路线
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
FirebaseDatabase firebaseDatabase = FirebaseDatabase.getInstance();
DatabaseReference myRef = firebaseDatabase.getReference("route");
try {
// Read from the database
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
// This method is called once with the initial value and again
// whenever data at this location is updated.
GenericTypeIndicator t = new GenericTypeIndicator () {};
List<Object> routes = (List<Object>) dataSnapshot.getValue(t);
if( routes == null ) {
Snackbar.make(view, "No value " ,Snackbar.LENGTH_LONG).setAction("Action", null).show();
}
else {
Snackbar.make(view, "The routes Size is " + routes.size(), Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
}
@Override
public void onCancelled(DatabaseError error) {
// Failed to read value
Log.w("BUS_TAG", "Failed to read value.", error.toException());
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
});
通过我得到的代码
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.rhcloud.escot.bsr, PID: 1750
com.google.firebase.database.DatabaseException: Not a direct subclass of GenericTypeIndicator: class com.google.firebase.database.GenericTypeIndicator
at com.google.android.gms.internal.zzalq.zza(Unknown Source)
at com.google.firebase.database.DataSnapshot.getValue(Unknown Source)
at com.rhcloud.escot.bsr.MainActivity$2$1.onDataChange(MainActivity.java:61)
at com.google.android.gms.internal.zzaih.zza(Unknown Source)
at com.google.android.gms.internal.zzajh.zzctc(Unknown Source)
at com.google.android.gms.internal.zzajk$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5631)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:959)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:754)
07-20 09:07:05.756 757-1407/? W/ActivityManager: Force finishing activity 1 com.rhcloud.escot.bsr/.MainActivity
我在阅读路线表时是否遗漏了什么
2条答案
按热度按时间goqiplq21#
我今天遇到了同样的问题,通过在ProGuard / R8配置中添加以下行得到了修复:
zaq34kh62#
而不是:
用这个