Reading BD Sqlite Android Studio (Kotlin)

Asked

Viewed 55 times

0

Next guys, I’m having a problem reading a data from the database, with the following method:

inserir a descrição da imagem aqui

But I have this little problem on line 68. Where are you saying you expect a value like Tipo() and I’m passing a String, only when I place referencing my class Tipo() thus:

t. type = result.getString(result.getColumnIndex(COL_TIPO)). Type

He doesn’t accept.

This is my kind of class:

enum class Tipo {
    RECEITA
    {
        override fun toString(): String
        {
            return "RECEITA"
        }
    },
    DESPESA
    {
        override fun toString(): String
        {
            return "DESPESA"
        }
    }

}

If anyone has any ideas, or a better method for reading.

This is my Transacao model in which I have my attributes:

class Transacao(var valor: BigDecimal,
                var categoria: String = "Indefinida",
                var tipo: Tipo,
                var data: Calendar = Calendar.getInstance()) {

}

1 answer

0

All I had to do was declare Tipo after equal and receive a valueOf of the string type, being as follows:

t.tipo = Tipo.valueOf(result.getString(result.getColumnIndex(COL_TIPO)).toString())

Browser other questions tagged

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