Variable problem (Kotlin)

Asked

Viewed 30 times

0

Hello, I’m doing an android Studio project with Kotlin and I’m having the following error.

equal.setOnClickListener {
    try{
        val expressao = ExpressionBuilder(expressao.text.toString()).build()  

        val resultado = expressao.evaluate()
        val LongResult = resultado.toLong()

        if ( resultado == LongResult.toDouble()) {
            result.text = LongResult.toString()
        }else{
            result.text = resultado.toString()
        }

    }catch (e: Exception) {

    }
}

Specifically in this part (expression.text.toString()). build() I’m having trouble adding expression in expression.text.toString.

If anyone can help me, I’d appreciate it.

  • I forgot to mention that is giving error in the compilation Unresolved Reference: expression

  • In the same line where you declare the variable expressao, you try to use it, that’s the problem, so Unresolved reference.

  • How would I solve such a problem then ? you can show me with codes ?

  • 2

    No one can solve this problem for you, there is no context to know what you try to do. Also, I have never used ExpressionBuilder. What I can tell you is that you need to figure out where to get this initial value for the ExpressionBuilder, because clearly it should not be of a variable that has not yet been declared.

  • The worst q I saw a guy doing exactly the same code on youtube, in it everything works out, but in my project gives this error.

  • And only gave this error when I tried to emulate the app in android studio.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.