Frage

I was able to print out to the log cat for debugging yesterday, but for some reason it will not show up today.

I am trying to get the id of an image button.

In my onClickListener for the button:

clicker = new OnClickListener() {
    @Override
    public void onClick(View v) {
        ImageButton clicked = (ImageButton) v;
        makeMove(clicked.getId());

        System.out.print("ID is:"+clicked.getId());
    }
};

Would there be any reason why it would not show up on LogCat? I tried to set a filter to just SystemOut but got nothing.

Have you got any tips on getting it to output?

War es hilfreich?

Lösung

To print into LogCat, replace System.out.print() method with Log.i(), Log.d() or Log.w() method as like below...

System.out.print("ID is:"+clicked.getId());

with

Log.i("ID is:", " "+clicked.getId());

Because, System.out.print() is designed to print in the Console and Log.i() is designed to print in the LogCat.

So, to print in the LogCat, you should use Log class and its methods. The Log class's methods maintain some TAG as their first argument which helps to sort-out printed log in the LogCat.

Andere Tipps

Why you aren't using the

Log.d(TAG, stirng)

instead of

System.out.print()?

Always use Log.i() in order to print logs in Android.

Log.i("ID is: ", "" + clicked.getId());
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top