Pregunta

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;
}

}
¿Fue útil?

Solución

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.

Otros consejos

As @free3om hinted at, Log.* can be used to print out many different outputs to the Logcat. If you want to see just errors, you can use Log.e(String s1, String s2) to see what and where something went wrong. Here's a link to the doc's for Log. http://developer.android.com/reference/android/util/Log.html

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top