0

The first two logs display fine, but the last one doesn't show up. Even if the second parameter of the last log has an issue, I'm still confused why the log doesn't just display with an error or something. Any help is appreciated.

@Override
public void onStart() {
    super.onStart();
    TextView country = (TextView) findViewById(R.id.country);
    Log.d("t1", "t1");
    Log.d("t2", country.toString());
    Log.d("t3", country.getText().toString());
}

Here is the log output:

02-07 05:10:16.877 23305-23305/---bundle id--- D/t1: t1
02-07 05:10:16.877 23305-23305/---bundle id--- D/t2: android.support.v7.widget.AppCompatTextView{381dd943 V.ED..C. ......I. 0,0-0,0 #7f0e0089 app:id/country}
Elliot Alderson
  • 546
  • 2
  • 17
  • 1
    Is the content of the textview empty? – OneCricketeer Feb 07 '16 at 13:26
  • The first parameter is called the tag so you can search for it easily in the logcat – OneCricketeer Feb 07 '16 at 13:34
  • Empty strings can be just as useful as regular strings. I don't see why log was designed to not display if the second parameter is an empty string. In this case, I have to concatenate a second tag onto the second parameter in order for anything to display. /endrant – Elliot Alderson Feb 07 '16 at 13:42
  • Worth noting that in the documentation the tag (first parameter) *usually identifies the class or activity where the log call occurs.* – OneCricketeer Feb 07 '16 at 13:47
  • Good to know, more so for system generated logs. I'm used to NSLog just displaying whatever goes in it, but android does things very differently I'm learning. Thanks. – Elliot Alderson Feb 07 '16 at 13:53
  • 1
    Welcome. My tags usually look like `MainActivity.class.getSimpleName()` which returns "MainActivity" and avoids the potential typo of a hard coded tag – OneCricketeer Feb 07 '16 at 13:57

2 Answers2

1

As far as I'm aware, if the getText() method of the TextView object returns an empty string, the logger will not output an entry for it. You can try concatenating some text to describe what should be expected in the output. For example:

Log.d("t3", "Country TextView Value: " + country.getText().toString());
Gideon Pyzer
  • 22,610
  • 7
  • 62
  • 68
0

This case is only possible with null string value return by TextView. You need to add something with Log as below :

Log.d("t3", "Country : " + country.getText().toString());
Rohit Suthar
  • 2,635
  • 1
  • 22
  • 27