1

i write a simple code in andorid

package com.hello.stringtest;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
        String x = "\r\nHello\r\nHello1\r\nHello2";
        Log.i("Hello", x);
        Toast.makeText(this,x,Toast.LENGTH_LONG).show();
    }

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

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

when i run this application i was expecting in Log line separated Hello Hello1 Hello2

but there is nothing in Logcat table .can anyone please explain why it's not showing in Logcat.

mathlearner
  • 7,509
  • 31
  • 126
  • 189

2 Answers2

4

When I try following code

    Log.i("ACTIVITY1", "\rCreated");
    Log.i("ACTIVITY2", "\nCreated");

only ACTIVITY2 appears in Logcat. I guess you issue is related to \r. Remove \r from your String x. Try \n instead.

Also see this. \r seems to be for old Mac OS versions.

Community
  • 1
  • 1
AlbAtNf
  • 3,859
  • 3
  • 25
  • 29
  • This solved my problem, thx. I am re-directing the output of a command line tool to logcat, and I could not get it to display. Turns out "Log" was silently throwing away my data (which had \r line endings) a simple addition of .replace("\r", "") to the String fixed it. – kshepherd Aug 27 '16 at 10:26
-1

That's because by default the Log.i takes up less priority when compared to log.d. TO check it out change your logcat window to info from debug here you can get a complete reference of the priority

The priority is one of the following character values, ordered from lowest to highest priority:
V — Verbose (lowest priority)
D — Debug
I — Info
W — Warning
E — Error
F — Fatal
S — Silent (highest priority, on which nothing is ever printed)

also this link might be useful http://developer.android.com/tools/debugging/debugging-log.html#startingLogcat

Aniruddha K.M
  • 7,361
  • 3
  • 43
  • 52