Benoit Adam
Benoit Adam

Reputation: 79

Kotlin Log.i and Log.e errors

I'm doing a basic training for Kotlin and Android Studio (4.1),

The training I follow is from 2018, may be already a bit old but I don't get why so basic function would not work.

I'm having a hard time trying to get logs to display in the "6:Logcat"

Here is my code:

package fr.benoitexample.blocnote

import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.util.Log import android.view.View

class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
    }

    fun addButtonTouched(button:View) {
        Log.i( tag:"banane", msg: "Coucou")
        Log.e( tag:"banane", msg: "Coucou")
    }

}

I'm getting this kind of error:

e: C:\Users\Benoit\AndroidStudioProjects\BlocNote\app\src\main\java\fr\benoitexample\blocnote\MainActivity.kt: (15, 21): Unexpected tokens (use ';' to separate expressions on the same line)

Upvotes: 1

Views: 2867

Answers (2)

jana
jana

Reputation: 266

The Log methods in android.util.Log take 2 String parameters (and optionally a Throwable as a third param) - you should write it like this:

Log.i("banane", "Coucou")

Upvotes: 3

saeedata
saeedata

Reputation: 947

You can't call Java methods with parameters name in Kotlin file

just simplify write this:

Log.i("banane", "Coucou")

Upvotes: 2

Related Questions