0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AndroidStudioでKotlinのprint()の文が表示されないとき

Last updated at Posted at 2018-05-26

AndroidStudioでKotlinを使っているとき、print()でデバッグ文を出力しようとしたのですが、なぜか表示されないという現象が起きました。

環境

  • AndoridStudio 3.1
  • Kotlin 1.2

まず、Kotlinでprint()は使えるのか

使えるようです。

他の環境で起きるのか

ブラウザ上でKotlinを使えるサイトでprint()を使ってみたところ、普通に表示されました。

https://try.kotlinlang.org/
https://paiza.io/ja

スクリーンショット 2018-05-26 20.03.42.png

しかし、ターミナル上でprint()を使ったKotlinのコードをコンパイルして表示してみたところ、

スクリーンショット 2018-05-26 19.44.21.png

このような結果になりました。なぜか「%」が後ろにくっついています。

なぜKotlinのprint()を使うと後ろに「%」がくっつくのかは謎です。
AndroidStudioでKotlinのprint()が表示されない現象との因果関係は不明です。

解消方法

print()ではなく、println()を使うことで表示されます。
また、以下のように最後にprintln()を使うとprint()の文も正常に表示されます。

fun main(args: Array<String>){
	print("hoge")
	print("fuga")
	println("piyo")
}

スクリーンショット 2018-05-26 19.56.49.png

print()を単独で使ったときにあった「%」がなくなってますね。
print()を使うと文に「%」がくっつき、AndroidStudioで表示されなくなってしまうということなのでしょうか。

まとめ

  • AndroidStudioではKotlinのprint()を使わない、使いたい場合は最後にprintln()を置く
  • デバッグ文を出したいときはprintln()、またはLogを使う
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?