Android Kotlin - Unexpected tokens (use ';' to separate expressions on the same line)

Viewed 7806

I found couple of answers for this but I don't understand what the hell they are talking about and what to do in my case.

This is the code:

Functions().(prefs!!.getLong("userid", 0), prefs!!.getString("notifToken", "")!!)

I get Unexpected tokens (use ';' to separate expressions on the same line) for prefs!!.getString("notifToken", "")!!

And in Functions class:

fun lastOnline(userid: Long, token: String){

    val params = RequestParams()
    params.put("userid", userid)
    params.put("token", token)

    val client = AsyncHttpClient()
    client.post("https://www.bla.com/do.php", params, object : JsonHttpResponseHandler()
    {
        override fun onSuccess(statusCode: Int, headers: Array<Header>?, response: JSONArray?)
        {

        }
        override fun onFailure(statusCode: Int, headers: Array<Header>?, e: Throwable, response: JSONArray?)
        {
            Log.d("pikabo", "error")
        }
    })
}

Please help!

3 Answers

Your code boils down to Functions().(), and that does not make a lot of sense. Functions() will create an instance of your Functions class. But then you seem to be missing a function name after the ..

I am going to guess that you are trying to call lastOnline(), in which case you need to use that function name:

Functions().lastOnline(prefs!!.getLong("userid", 0), prefs!!.getString("notifToken", "")!!)

If all looks good and still same error occurs pls check if there is any hidden character in the lines of code typed/pasted

Just remove the excess !! because it will never be null with a default value passed into.

Related