未能将java.lang.String类型的值转换为long



我在代码中没有看到错误,如果它能工作,有人能告诉我如何修复它吗?提前感谢:(欢迎提供任何帮助

public class ListPatrimony extends AppCompatActivity {

long money = 1;

public void onDataChange (DataSnapshot dataSnapshot) {
if (dataSnapshot.child ("money").getValue(Long.class) >= 7) <- line error
{ dataSnapshot.child ("money").getRef().setValue((money));

com.google.firebase.database.DatabaseException: Failed to convert a value of type java.lang.String to long
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.convertLong(com.google.firebase:firebase-database@@19.2.1:384)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToPrimitive(com.google.firebase:firebase-database@@19.2.1:295)
at com.google.firebase.database.core.utilities.encoding.CustomClassMapper.deserializeToClass(com.google.firebase:firebase-database@@19.2.1:214)
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.gangster.ui.activities.ListPatrimony$2$1.onDataChange(ListPatrimony.java:87)

似乎是在保存时将money保存到了String中。那么,你能改变吗:

if (dataSnapshot.child ("money").getValue(Long.class) >= 7)

if (dataSnapshot.child ("money").getValue().toLong() >= 7)

最新更新