java.lang.IllegalStateException:progressLayout不能为空

时间:2019-12-08 18:54:48

标签: android android-layout android-fragments kotlin

每次我更改标签时,我的应用程序崩溃,而前一个标签仍在加载并出现上述错误。

  

E /:[ZeroHung] zrhung_get_config:wp [0x0008] E /的获取配置失败:   [ZeroHung] zrhung_get_config:wp [0x0008] E /的获取配置失败:   [ZeroHung] zrhung_get_config:wp [0x0008]的获取配置失败   I /聊天:uid = 10335(com.yr.meetmefit)HeapTaskDaemon相同的1行   E /:[ZeroHung] zrhung_get_config:wp [0x0008]的配置失败   W / ClassMapper:在课堂上找不到熟练的设置者/领域   com.yr.meetmefit.util.User(字段/设置者区分大小写!)       在类com.yr.meetmefit.util.User上找不到preferredWorkoutLocation的设置器/字段(字段/设置者区分大小写!)       在类com.yr.meetmefit.util.User上找不到typeOfWorkout的设置器/字段(字段/设置者区分大小写!)       在类com.yr.meetmefit.util.User上找不到用于FitnessGoal的设置器/字段(字段/设置者区分大小写!)       在com.yr.meetmefit.util.User类上找不到ID的设置器/字段       在类com.yr.meetmefit.util.User上找不到用于FitnessGoalsId的设置器/字段(字段/设置者区分大小写!)   D / AndroidRuntime:关闭VM E / AndroidRuntime:致命异常:   主要       流程:com.yr.meetmefit,PID:25488       java.lang.IllegalStateException:noUsersLayout不能为null           在com.yr.meetmefit.fragments.SwipeFragment.populateItems(SwipeFragment.kt:162)           在com.yr.meetmefit.fragments.SwipeFragment $ onViewCreated $ 1.onDataChange(SwipeFragment.kt:72)           com.google.firebase.database.Query $ 1.onDataChange(com.google.firebase:firebase-database @@ 19.1.0:179)           com.google.firebase.database.core.ValueEventRegistration.fireEvent(com.google.firebase:firebase-database @@ 19.1.0:75)           com.google.firebase.database.core.view.DataEvent.fire(com.google.firebase:firebase-database @@ 19.1.0:63)           com.google.firebase.database.core.view.EventRaiser $ 1.run(com.google.firebase:firebase-database @@ 19.1.0:55)           在android.os.Handler.handleCallback(Handler.java:907)           在android.os.Handler.dispatchMessage(Handler.java:105)           在android.os.Looper.loop(Looper.java:216)           在android.app.ActivityThread.main(ActivityThread.java:7625)           在java.lang.reflect.Method.invoke(本机方法)           在com.android.internal.os.RuntimeInit $ MethodAndArgsCaller.run(RuntimeInit.java:524)           在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)   I / OpenGLRenderer:戴维!持续时间= 2900ms;标志= 0,   IntendedVsync = 31039276901138,Vsync = 31039693567788,   OldestInputEvent = 9223372036854775807,NewestInputEvent = 0,   HandleInputStart = 31039708966612,AnimationStart = 31039709060362,   PerformTraversalsStart = 31039709958800,DrawStart = 31042094212445,   SyncQueued = 31042129277029,SyncStart = 31042129370258,   IssueDrawCommandsStart = 31042130287966,SwapBuffers = 31042175786404,   FrameCompleted = 31042177035362,DequeueBufferDuration = 418000,   QueueBufferDuration = 269000,I / Process:正在发送信号。 PID:25488   SIG:9进程25488已终止。

有人可以帮助我解决崩溃问题吗?

代码

[class SwipeFragment : Fragment() {

    private var callback: MeetMeFitCallback? = null
    private lateinit var userId: String
    private lateinit var userDatabase: DatabaseReference
    private lateinit var chatDatabase: DatabaseReference
    private var cardsAdapter: ArrayAdapter<User>? = null
    private var rowItems = ArrayList<User>()
    private var preferredGender: String? = null
    private var location: String? = null
    private var userName: String? = null
    private var imageUrl: String? = null


    fun setCallBack(callback: MeetMeFitCallback) {
        this.callback = callback

        userId = callback.onGetUserId()
        userDatabase = callback.onGetUserDatabase()
        chatDatabase = callback.getChatDatabase()


    }

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_swipe, container, false)
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)

        userDatabase.child(userId).addListenerForSingleValueEvent(object : ValueEventListener {
            override fun onCancelled(p0: DatabaseError) {
            }

            override fun onDataChange(p0: DataSnapshot) {

                val user = p0.getValue(User::class.java)
                preferredGender = user?.preferredGender
                userName = user?.name
                location = user?.location
                imageUrl = user?.imageUrl
                populateItems()

            }
        })

        //Create adapter and start displaying elements on the screen

        cardsAdapter = CardsAdapter(context, R.layout.item, rowItems)

        frame.adapter = cardsAdapter

        frame.setFlingListener(object : SwipeFlingAdapterView.onFlingListener {
            override fun removeFirstObjectInAdapter() {
                rowItems.removeAt(0)
                cardsAdapter?.notifyDataSetChanged()
            }

            override fun onLeftCardExit(p0: Any?) {
                var user = p0 as User
                userDatabase.child(user.uid.toString()).child(DATA_SWIPES_LEFT).child(userId)
                    .setValue(true)
            }

            override fun onRightCardExit(p0: Any?) {
                val selectedUser = p0 as User
                val selectedUserId = selectedUser.uid
                if (!selectedUserId.isNullOrEmpty()) {
                    userDatabase.child(userId).child(DATA_SWIPES_RIGHT)
                        .addListenerForSingleValueEvent(object : ValueEventListener {
                            override fun onCancelled(p0: DatabaseError) {
                            }

                            override fun onDataChange(p0: DataSnapshot) {
                                if (p0.hasChild(selectedUserId)) {
                                    Toast.makeText(context, "Match! You can now chat!", Toast.LENGTH_SHORT).show()

                                    //Key Generation for Chat Database
                                    val chatKey = chatDatabase.push().key
                                    if (chatKey != null) {
                                        userDatabase.child(userId).child(DATA_SWIPES_RIGHT)
                                            .child(selectedUserId).removeValue()
                                        userDatabase.child(userId).child(DATA_MATCHES)
                                            .child(selectedUserId).setValue(chatKey)
                                        userDatabase.child(selectedUserId).child(DATA_MATCHES)
                                            .child(userId).setValue(chatKey)

                                        chatDatabase.child(chatKey).child(userId).child(DATA_NAME)
                                            .setValue(userName)
                                        chatDatabase.child(chatKey).child(userId)
                                            .child(DATA_IMAGE_URL).setValue(imageUrl)



                                        chatDatabase.child(chatKey).child(selectedUserId)
                                            .child(DATA_NAME).setValue(selectedUser.name)
                                        chatDatabase.child(chatKey).child(selectedUserId)
                                            .child(DATA_IMAGE_URL).setValue(selectedUser.imageUrl)
                                    }
                                } else {
                                    userDatabase.child(selectedUserId).child(DATA_SWIPES_RIGHT)
                                        .child(userId).setValue(true)
                                }
                            }
                        })
                }
            }

            override fun onAdapterAboutToEmpty(p0: Int) {
            }

            override fun onScroll(p0: Float) {
            }
        })

        frame.setOnItemClickListener { position, data -> }

        likeButton.setOnClickListener {
            if (!rowItems.isEmpty()) {
                frame.topCardListener.selectRight()
            }
        }

        dislikeButton.setOnClickListener {
            if (!rowItems.isEmpty()) {
                frame.topCardListener.selectLeft()
            }
        }
    }

    fun populateItems() {
        noUsersLayout.visibility = View.GONE
        progressLayout.visibility = View.VISIBLE
        val cardsQuery = userDatabase.orderByChild(DATA_LOCATION).equalTo(location)
            //.also{ userDatabase.orderByChild(DATA_GENDER).equalTo(preferredGender) }
        cardsQuery.addListenerForSingleValueEvent(object : ValueEventListener {
            override fun onCancelled(p0: DatabaseError) {

            }

            override fun onDataChange(p0: DataSnapshot) {
                p0.children.forEach { child ->
                    val user = child.getValue(User::class.java)
//                    if (user != null ) {
//                        val cardsQuery1 = userDatabase.orderByChild(DATA_GENDER).equalTo(preferredGender)
//                        cardsQuery1.addListenerForSingleValueEvent( object : ValueEventListener{
//                            override fun onCancelled(p0: DatabaseError) {
//
//                            }

                           // override fun onDataChange(p0: DataSnapshot) {
                                var showUser = true
                                if (child.child(DATA_SWIPES_LEFT).hasChild(userId) ||
                                    child.child(DATA_SWIPES_RIGHT).hasChild(userId) ||
                                    child.child(DATA_MATCHES).hasChild(userId)){
                                    showUser = false
                                }
                                if (showUser) {
                                    rowItems.add(user!!)
                                    cardsAdapter?.notifyDataSetChanged()
                                }
                            //}

                    progressLayout.visibility = View.GONE
                    if (rowItems.isEmpty()) {
                        noUsersLayout.visibility = View.VISIBLE
                    }

                        }

                    }
                })



  }

}][1]

0 个答案:

没有答案