addListenerForSingleValueEvent не получает данные из базы данных - PullRequest
0 голосов
/ 14 января 2020

Я новичок в Kotlin и разработке мобильных приложений, поэтому я решил начать изучать его, написав большой проект, такой как Instagram. Итак, я начал писать EditProfileActivity, и он должен извлекать данные из базы данных. Но по какой-то причине он просто не делает этого. Прошу прощения за глупый вопрос, но я был бы очень рад его исправить!

package com.example.instagram

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.TextView
import com.example.instagram.models.User
import com.google.firebase.auth.FirebaseAuth
import com.google.firebase.database.*
import kotlinx.android.synthetic.main.activity_edit_profile.*

class EditProfileActivity : AppCompatActivity() {
    private val TAG = "EditProfileActivity"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_edit_profile)

        Log.d(TAG, "onCreate: ")

        close_image.setOnClickListener{
            finish()
        }

        val auth = FirebaseAuth.getInstance()
        val user = auth.currentUser

        val dataRef = FirebaseDatabase.getInstance().getReference("users").child(user!!.uid)

        dataRef.addListenerForSingleValueEvent(object: ValueEventListener {
            override fun onDataChange(data: DataSnapshot) {
                Log.d(data.exists().toString(), "onDataChange: ")
                val user = data.getValue(User::class.java)
                name_input.setText(user!!.name, TextView.BufferType.EDITABLE)
                username_input.setText(user.username, TextView.BufferType.EDITABLE)
                website_input.setText(user.website, TextView.BufferType.EDITABLE)
                bio_input.setText(user.bio, TextView.BufferType.EDITABLE)
                email_input.setText(user.email, TextView.BufferType.EDITABLE)
                phone_input.setText(user.phone.toString(), TextView.BufferType.EDITABLE)
            }

            override fun onCancelled(error: DatabaseError) {
                Log.e(TAG, "onCancelled: ", error.toException())
            }
        })
        Log.d(TAG, "Finished: ")
    }
}

Обновление (структура базы данных): enter image description here

Вывод отладчика

V/FA: Recording user engagement, ms: 294829
V/FA: Connecting to remote service
V/FA: Activity paused, time: 28090607
V/FA: Activity resumed, time: 28090656
D/FA: Logging event (FE): screen_view(_vs), Bundle[{ga_event_origin(_o)=auto, ga_previous_class(_pc)=EditProfileActivity, ga_previous_id(_pi)=-387721556240172959, ga_screen_class(_sc)=ProfileActivity, ga_screen_id(_si)=-387721556240172960}]
V/FA: Connection attempt already in progress
V/FA: Connection attempt already in progress
D/FA: Logging event (FE): user_engagement(_e), Bundle[{ga_event_origin(_o)=auto, engagement_time_msec(_et)=294829, ga_screen_class(_sc)=EditProfileActivity, ga_screen_id(_si)=-387721556240172959}]
V/FA: Connection attempt already in progress
D/EGL_emulation: eglMakeCurrent: 0xdc1d3c60: ver 3 1 (tinfo 0xc519f5a0)
D/EGL_emulation: eglMakeCurrent: 0xdc1d3c60: ver 3 1 (tinfo 0xc519f5a0)
D/EGL_emulation: eglMakeCurrent: 0xdc1d3c60: ver 3 1 (tinfo 0xc519f5a0)
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 4
V/FA: Inactivity, disconnecting from the service
W/ActivityThread: handleWindowVisibility: no activity for token android.os.BinderProxy@c686383
V/FA: Recording user engagement, ms: 16391
V/FA: onActivityCreated
V/FA: Connecting to remote service
V/FA: Activity paused, time: 28107045
D/FA: Logging event (FE): user_engagement(_e), Bundle[{ga_event_origin(_o)=auto, engagement_time_msec(_et)=16391, ga_screen_class(_sc)=ProfileActivity, ga_screen_id(_si)=-387721556240172960}]
V/FA: Connection attempt already in progress
D/EditProfileActivity: onCreate: 
D/EditProfileActivity: Finished: 
V/FA: Activity resumed, time: 28108063
I/Choreographer: Skipped 66 frames!  The application may be doing too much work on its main thread.
D/FA: Logging event (FE): screen_view(_vs), Bundle[{ga_event_origin(_o)=auto, ga_previous_class(_pc)=ProfileActivity, ga_previous_id(_pi)=-387721556240172960, ga_screen_class(_sc)=EditProfileActivity, ga_screen_id(_si)=-387721556240172958}]
V/FA: Connection attempt already in progress
V/FA: Connection attempt already in progress
D/EGL_emulation: eglMakeCurrent: 0xdc1d3c60: ver 3 1 (tinfo 0xc519f5a0)
I/OpenGLRenderer: Davey! duration=2129ms; Flags=1, IntendedVsync=28107096282360, Vsync=28108196282316, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=28108204337360, AnimationStart=28108204898260, PerformTraversalsStart=28108214179960, DrawStart=28109176033060, SyncQueued=28109221244360, SyncStart=28109251250960, IssueDrawCommandsStart=28109251346160, SwapBuffers=28109252425360, FrameCompleted=28109255399160, DequeueBufferDuration=864000, QueueBufferDuration=460000, 
D/EGL_emulation: eglMakeCurrent: 0xdc1d3c60: ver 3 1 (tinfo 0xc519f5a0)
I/OpenGLRenderer: Davey! duration=2170ms; Flags=1, IntendedVsync=28107096282360, Vsync=28108196282316, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=28108204337360, AnimationStart=28108204898260, PerformTraversalsStart=28108214179960, DrawStart=28109258477660, SyncQueued=28109259177160, SyncStart=28109364208560, IssueDrawCommandsStart=28109364441760, SwapBuffers=28109366543960, FrameCompleted=28109372051660, DequeueBufferDuration=1478000, QueueBufferDuration=3537000, 
I/Choreographer: Skipped 61 frames!  The application may be doing too much work on its main thread.
D/EGL_emulation: eglMakeCurrent: 0xdc1d3c60: ver 3 1 (tinfo 0xc519f5a0)
I/OpenGLRenderer: Davey! duration=1040ms; Flags=0, IntendedVsync=28108344898334, Vsync=28109361564960, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=28109373518860, AnimationStart=28109373627860, PerformTraversalsStart=28109374470360, DrawStart=28109376609960, SyncQueued=28109378076460, SyncStart=28109379599160, IssueDrawCommandsStart=28109379779660, SwapBuffers=28109385523960, FrameCompleted=28109387255660, DequeueBufferDuration=65000, QueueBufferDuration=281000, 
D/FA: Connected to remote service
V/FA: Processing queued up service tasks: 4
V/FA: Inactivity, disconnecting from the service

Я подключил свое собственное устройство к android studio и как-то на нем работает. Возможно, была проблема с моим эмулятором android. Спасибо за все ваши проблемы.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...