I need to print some str to console (Android Studio) using Kotlin. I've tried the:

Log.v() 
Log.d() 
Log.i() 
Log.w() 
Log.e() 

methods. But it seems to work only on Java. What should I use to print using Kotlin? Thanks

推荐答案

有两种方法.

You can use 100 for example but first you need to import Log

import android.util.Log

{...}

Log.d("TAG", "message")

{...}

资料来源:https://developer.android.com/reference/android/util/Log.html

You can also use kotlin's print and println function.

例子:

{...}

print("message")

println("other message")

{...}

Source: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/

Kotlin相关问答推荐

Kotlin-删除按钮周围的空格

如何确保Kotlin子类已完成初始化?

在Jetpack Compose中创建波浪式文本动画:顺序中断问题

为什么Kotlin协程程序即使有延迟也能输出?

有没有一种简单的方法来识别物体?

为什么在jacksonObjectMapper上将DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES设置为false无效?

Android Jetpack Compose:在空的 Compose 活动中找不到 OutlinedTextField (Material3)

如何为你的 Flutter 元素添加 Kotlin 支持?

如何修复 ViewPager2 中的Design assumption violated错误?

防止导航到同一个片段

什么是开放式property?为什么我不能将其设置器设为private私有?

Kotlin 中的内联构造函数是什么?

创建Spring和#180的实例;Kotlin中的参数化类型引用

保存对象时未填充 Spring Boot JPA@CreatedDate @LastModifiedDate

如何限制kotlin协程的最大并发性

如何使用mockk库模拟android上下文

uses-sdk:minSdkVersion 16 不能小于库中声明的版本 23

如何根据ArrayList的对象属性值从中获取最小/最大值?

Failure delivering result on activity result

Dagger 2 androidx fragment不兼容类型