【发布时间】:2020-06-24 07:55:19
【问题描述】:
我正在尝试使用 Datasnapshot 添加每个列表的成本,然后将其发送到 firebase,然后再次使用发送的数据到另一个活动中,但我的应用打开然后崩溃并抛出以下错误。
2020-03-12 14:43:13.887 17284-17284/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.android.zfr, PID: 17284
com.google.firebase.database.DatabaseException: Failed to convert value of type java.lang.Long to String
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertString(com.google.firebase:firebase-database@@19.2.1:425)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@19.2.1:216)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertToCustomClass(com.google.firebase:firebase-database@@19.2.1:79)
at com.google.firebase.database.DataSnapshot.getValue(com.google.firebase:firebase-database@@19.2.1:203)
at com.example.android.zfr.NavActivity$2.onDataChange(NavActivity.java:71)
at com.google.firebase.database.Query$1.onDataChange(com.google.firebase:firebase-database@@19.2.1:179)
at com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database@@19.2.1:75)
at com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database@@19.2.1:63)
at com.google.firebase.database.core.view.EventRaiser$1.run(com.google.firebase:firebase-database@@19.2.1:55)
at android.os.Handler.handleCallback(Handler.java:794)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:176)
at android.app.ActivityThread.main(ActivityThread.java:6651)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:824)
这是我使用数据的活动代码
nDb=database.getReference().child("Navigation Activity").child("Cost");
nDb.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
String cost=dataSnapshot.getValue(String.class);
Log.d(TAG, "Value is: " + cost);
nav_total_cost.setText(cost);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
请不要因为我的错误而评判我。
【问题讨论】:
标签: java android json firebase-realtime-database