Home » Android » java – Why doesn't "System.out.println" work in Android?

java – Why doesn't "System.out.println" work in Android?

Posted by: admin March 10, 2020 Leave a comment


I want to print something in console, so that I can debug it. But for some reason, nothing prints in my Android application.

How do I debug then?

public class HelloWebview extends Activity {
    WebView webview;    
    private static final String LOG_TAG = "WebViewDemo";
    private class HelloWebViewClient extends WebViewClient {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return true;

    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {
        webview = (WebView) findViewById(R.id.webview);
        webview.setWebViewClient(new HelloWebViewClient());
        webview.setWebChromeClient(new MyWebChromeClient());
        System.out.println("I am here");
How to&Answers:


On the emulator and most devices System.out.println gets redirected to LogCat and printed using Log.i(). This may not be true on very old or custom Android versions.


There is no console to send the messages to so the System.out.println messages get lost. In the same way this happens when you run a “traditional” Java application with javaw.

Instead, you can use the Android Log class:

Log.d("MyApp","I am here");

You can then view the log either in the Logcat view in Eclipse, or by running the following command:

adb logcat

It’s good to get in to the habit of looking at logcat output as that is also where the Stack Traces of any uncaught Exceptions are displayed.

The first Entry to every logging call is the log tag which identifies the source of the log message. This is helpful as you can filter the output of the log to show just your messages. To make sure that you’re consistent with your log tag it’s probably best to define it once as a static final String somewhere.

Log.d(MyActivity.LOG_TAG,"Application started");

There are five one-letter methods in Log corresponding to the following levels:

  • e() – Error
  • w() – Warning
  • i() – Information
  • d() – Debug
  • v() – Verbose
  • wtf() – What a Terrible Failure

The documentation says the following about the levels:

Verbose should never be compiled into an application except during development. Debug logs are compiled in but stripped at runtime. Error, warning and info logs are always kept.


Use the Log class. Output visible with LogCat


Yes it does. If you’re using the emulator, it will show in the Logcat view under the System.out tag. Write something and try it in your emulator.


Of course, to see the result in logcat, you should set the Log level at least to “Info” (Log level in logcat); otherwise, as it happened to me, you won’t see your output.


if you really need System.out.println to work(eg. it’s called from third party library). you can simply use reflection to change out field in System.class:

    Field outField = System.class.getDeclaredField("out");
    Field modifiersField = Field.class.getDeclaredField("accessFlags");
    modifiersField.set(outField, outField.getModifiers() & ~Modifier.FINAL);
    outField.set(null, new PrintStream(new RedirectLogOutputStream()); 
}catch(NoSuchFieldException e){
}catch(IllegalAccessException e){

RedirectLogOutputStream class:

public class RedirectLogOutputStream extends OutputStream{
    private String mCache;

    public void write(int b) throws IOException{
        if(mCache == null) mCache = "";

        if(((char) b) == '\n'){
            Log.i("redirect from system.out", mCache);
            mCache = "";
            mCache += (char) b;


There is no place on your phone that you can read the System.out.println();

Instead, if you want to see the result of something either look at your logcat/console window or make a Toast or a Snackbar (if you’re on a newer device) appear on the device’s screen with the message 🙂
That’s what i do when i have to check for example where it goes in a switch case code! Have fun coding! 🙂


it is not displayed in your application… it is under your emulator’s logcat


System.out.println(“…”) is displayed on the Android Monitor in Android Studio


I’ll leave this for further visitors as for me it was something about the main thread being unable to System.out.println.

public class LogUtil {

private static String log = "";
private static boolean started = false;
public static void print(String s) {
    //Start the thread unless it's already running
    if(!started) {
    //Append a String to the log
    log += s;

public static void println(String s) {
    //Start the thread unless it's already running
    if(!started) {
    //Append a String to the log with a newline.
    //NOTE: Change to print(s + "\n") if you don't want it to trim the last newline.
    log += (s.endsWith("\n") )? s : (s + "\n");

private static void start() {
    //Creates a new Thread responsible for showing the logs.
    Thread thread = new Thread(new Runnable() {
        public void run() {
            while(true) {
                //Execute 100 times per second to save CPU cycles.
                try {
                } catch (InterruptedException e) {
                //If the log variable has any contents...
                if(!log.isEmpty()) {
                    //...print it and clear the log variable for new data.
                    log = "";
    started = true;

Usage: LogUtil.println("This is a string");


Recently I noticed the same issue in Android Studio 3.3. I closed the other Android studio projects and Logcat started working. The accepted answer above is not logical at all.