gamma sava
gamma sava

Reputation: 33

Lambda causes unexpected token

I'm having a problem because of lambda. It says that it has unexpected tokens but there are no helpful solutions in the debugger. I am new to programming and I have no idea what to do especially because in the tutorial I follow it's the same thing with no errors. The code and the screenshot are bellow. Thanks

image

        when {
            getButtonText == "Edit Profile" -> startActivity(
                Intent(
                    context,
                    AccountSettingsActivity::class.java
                )
            )

            getButtonText == "Follow" -> {
                firebaseUser?.uid.let { it1 ->
                    FirebaseDatabase.getInstance().reference
                        .child("Follow").child(it1.toString())
                        .child("Following").child(profileId)
                        .setValue(true)
                }

                firebaseUser?.uid.let { it1 ->
                    FirebaseDatabase.getInstance().reference
                        .child("Follow").child(profileId)
                        .child("Followers").child(it1.toString())
                        .setValue(true)
                }
            }
        }

        getButtonText == "Following" ->  {

        firebaseUser?.uid.let { it1 ->
            FirebaseDatabase.getInstance().reference
                .child("Follow").child(it1.toString())
                .child("Following").child(profileId)
                .removeValue()
        }

        firebaseUser?.uid.let { it1 ->
            FirebaseDatabase.getInstance().reference
                .child("Follow").child(profileId)
                .child("Followers").child(it1.toString())
                .removeValue()
        }
    }

    }

Upvotes: 1

Views: 274

Answers (1)

Adrian K
Adrian K

Reputation: 4823

 } <<<< 

 getButtonText == "Following" ->

The marked bracket is closing the when block and should be removed. When using Android Studio you should be able to hit Ctrl+Alt+L to auto fix your formatting, including indentation. This will probably help you spot these kind of mistakes in the future

Upvotes: 1

Related Questions