1

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)
4
  • Do you have the logger set to the appropriate log level? You can choose between "error" ,"warn, "info" and so on Commented Nov 25, 2020 at 16:26
  • Yes I'm aware of that. The error displays when building app. Commented Nov 25, 2020 at 16:28
  • Which line is line 15? Commented Nov 25, 2020 at 16:29
  • Log.i( tag: "banane", msg: "Coucou") Commented Nov 25, 2020 at 16:41

2 Answers 2

3

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")

Sign up to request clarification or add additional context in comments.

Comments

2

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

just simplify write this:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.