我收到错误com.google.firebase.database.DatabaseException: Failed to convert value of type java.lang.Long to String in line 53这条线是var note = n.getValue(Note::class.java)我已经被这个错误困住了一段时间,因为我对编码还不够新,我不知道该怎么做,感谢任何帮助,非常感谢package com.example.gearoidodonovan.booksimport android.app.AlertDialogimport android.support.v7.app.AppCompatActivityimport android.os.Bundleimport android.renderscript.Samplerimport android.widget.Toastimport com.google.firebase.database.*import kotlinx.android.synthetic.main.activity_main.*import kotlinx.android.synthetic.main.add_note.view.*import java.text.SimpleDateFormatimport java.util.*class MainActivity : AppCompatActivity() { var mRef:DatabaseReference? = null var mNoteList:ArrayList<Note>?= null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) val database = FirebaseDatabase.getInstance() mRef = database.getReference("Notes") mNoteList = ArrayList() add_new_note.setOnClickListener { showDialogAddNote() } } override fun onStart(){ super.onStart() mRef?.addValueEventListener(object : ValueEventListener{ override fun onCancelled(p0: DatabaseError) { } override fun onDataChange(p0: DataSnapshot) { for (n in p0!!.children) { var note = n.getValue(Note::class.java) mNoteList?.add(note!!) } val noteAdapter = NoteAdapter(applicationContext, mNoteList!!) note_list_view.adapter = noteAdapter } }) }
2 回答

翻翻过去那场雪
TA贡献2065条经验 获得超14个赞
您的订单属性class note如下
var id:String?= null
var note:long?= null
var timestamp: String? = null
var title:String? = null```

qq_笑_17
TA贡献1818条经验 获得超7个赞
您收到此错误是因为您的 firebase 节点中有一个 long 类型的字段,您将其保存在 String 中。确保数据类型与 firebase 节点和您的数据类中的数据类型相同。
我认为大多数情况下 id 的数据类型都是 long ,您可以检查并据此更改 Note 的数据类
添加回答
举报
0/150
提交
取消