Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console of my Android Studio does not print the log message

I created a Hello, World project in Android Studio to test using System.out.println(). I believe the log message should be printed in the console, but it wasn't. Im using Android Studio AI-130.737825 with JRE:1.7.0_25. The test code follows:

package com.example.consoletest;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    System.out.println("please print me in the console");
    setContentView(R.layout.activity_main);

}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

}
like image 711
lu yuan Avatar asked Aug 25 '13 09:08

lu yuan


1 Answers

The console is not "connected" to the running app because it is run on a different system (be it an emulator, or physical device). The only "connected" part in Android Studio is the LogCat, which can be accessed using the Android tab at the bottom of the IDE.

You should rather print output to LogCat using the Log.* methods, which provides a lot more control and information, in almost the same simplistic way. Additionally, the logcat can be filtered to find exactly what you want.

like image 198
free3dom Avatar answered Oct 11 '22 00:10

free3dom