Kotlin: Expression 'length' of type 'Int' cannot be invoked as a function. The function 'invoke()' is not found

All of those int-returning methods (String#length(),...) have some time ago became properties. Just remove parenthesis () and use it in properties manner.

    var start = 0
    var end = s.length  //without ()

btw. String already has a method trim()

charAt should be replaced with [] operator. So replace s.charAt(end-1) with s[end-1]


In Kotlin the expressions getter and setter differ from Java in the absence of parentheses.

getter: #Class.method setter: #Class.method = value

e.g.

From: competitions.value(body?.competitionsList).

To: competitions.value = body?.competitionsList

e.g. 2:

// Gets linearlayout
  val layout: LinearLayout = findViewById(R.id.myLayout)
// Gets the layout params that will allow you to resize the layout
  val params: ViewGroup.LayoutParams = layout.layoutParams
  params.width = 100
  params.height = 100
  layout.layoutParams = params

Source

Tags:

Android

Kotlin