How to print to the console in Android Studio?

JavaAndroidMobileDevelopment EnvironmentAndroid Studio

Java Problem Overview


I just downloaded Android Studio for Linux from: http://developer.android.com/sdk/installing/studio.html

I'm wondering how to print to the console?

Neither System.out.print(...) nor Log.e(...) from android.util.Log seem to work.

Java Solutions


Solution 1 - Java

Run your application in debug mode by clicking on

enter image description here

in the upper menu of Android Studio.

In the bottom status bar, click 5: Debug button, next to the 4: Run button.

Now you should select the Logcat console.

In search box, you can type the tag of your message, and your message should appear, like in the following picture (where the tag is CREATION):

enter image description here

Check this article for more information.

Solution 2 - Java

Android has its own method of printing messages (called logs) to the console, known as the LogCat.

When you want to print something to the LogCat, you use a Log object, and specify the category of message.

The main options are:

  • DEBUG: Log.d
  • ERROR: Log.e
  • INFO: Log.i
  • VERBOSE: Log.v
  • WARN: Log.w

You print a message by using a Log statement in your code, like the following example:

Log.d("myTag", "This is my message");

Within Android Studio, you can search for log messages labelled myTag to easily find the message in the LogCat. You can also choose to filter logs by category, such as "Debug" or "Warn".

Solution 3 - Java

Android Studio 3.0 and earlier:

If the other solutions don't work, you can always see the output in the Android Monitor.


android studio screen shot


Make sure to set your filter to Show only selected application or create a custom filter.

enter image description here

Solution 4 - Java

You can see the println() statements in the Run window of Android Studio.

See detailed answer with screenshot here.

Solution 5 - Java

Be careful when using Logcat, it will truncate your message after ~4,076 bytes which can cause a lot of headache if you're printing out large amounts of data.

To get around this you have to write a function that will break it up into multiple parts like so.

Solution 6 - Java

If your app is launched from device, not IDE, you can do later in menu: Run - Attach Debugger to Android Process.

This can be useful when debugging notifications on closed application.

Solution 7 - Java

I had solve the issue by revoking my USB debugging authorizations.

To Revoke,

Go to Device Settings > Enable Developer Options > Revoke USB debugging authorizations

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTyrickView Question on Stackoverflow
Solution 1 - JavaBrandon S. LeeView Answer on Stackoverflow
Solution 2 - JavaRogueBanelingView Answer on Stackoverflow
Solution 3 - JavaDerek SoikeView Answer on Stackoverflow
Solution 4 - JavaShailendra MaddaView Answer on Stackoverflow
Solution 5 - JavaJosh CorreiaView Answer on Stackoverflow
Solution 6 - JavaZonView Answer on Stackoverflow
Solution 7 - JavaJay MungaraView Answer on Stackoverflow