0

As stated in the title, why can't I see System.out.println output inthe LogCat? This is my code which doesn't work. I use Android Studio (v.0.8.2).

EDIT: add log.i to code don't return nothing in logcat.

Here is my logcat

enter image description here

And here is my code

private static final String TAG = "MyActivity";

/*

*/

public void mButton(View view) {
    URLConnection nbpUrl;
    String data = "";
    try {
        nbpUrl = new URL("http://www.nbp.pl/Kursy/xml/dir.txt").openConnection();
        InputStream is = nbpUrl.getInputStream();
        BufferedReader reader = new BufferedReader(new InputStreamReader(is));
        String inputLine;
        while ((inputLine = reader.readLine()) != null) {
            if (inputLine.startsWith("a") && inputLine.endsWith("140807")) {
                System.out.println(inputLine);
                data = inputLine;
                Log.i(TAG, "test");
            }
        }
        is.close();
    }
    catch(Exception e){
        e.printStackTrace();
    }
    poleTextowe = (TextView)findViewById(R.id.pole1);
    poleTextowe.setText(data);
}
shadow
  • 1
  • 1
  • 3
  • See this,http://stackoverflow.com/questions/2220547/why-doesnt-system-out-println-work-in-android – nobalG Aug 12 '14 at 12:15

4 Answers4

1

dont use system out println. Android has its own Logger class. Please refer to that doc.

  • Don't post this as an answer, for it isn't. Post it as a comment – stealthjong Aug 12 '14 at 12:11
  • 1
    and how it is not an answer? you dont use syso in android, you use Log class for that purpose. – Marcin Mikołajczyk Aug 12 '14 at 12:13
  • @stealthjong I have to say, this is an answer. As it addresses the problem of not being able to see log messages in Logcat. And informs the OP that he is using the wrong api. An example would be nice though. – IAmGroot Aug 12 '14 at 12:16
  • It is possible though, even though Log.d() is better or preferred. OP doesnt ask how to print stuff in the Logcat, but how to print stuff in logcat with sysout. I sure do prefer sysout because youre not bound to Strings (with `Log.d(String, String)` you can't simply print one int) and you dont have to use double params all the time. – stealthjong Aug 12 '14 at 12:40
1

Try using

    Log.i(inputLine);

for more details you can refer to

http://developer.android.com/reference/android/util/Log.html

IAmGroot
  • 13,760
  • 18
  • 84
  • 154
krunal patel
  • 2,369
  • 1
  • 11
  • 11
1

System.out.println is a base Java way of printing out and does not tell the Dalvik VM to send it to the debugging device.

You need to use android.util.log then you can use

Log.w("myApp", "warning");
Log.e("myApp", "error");
Log.d("myApp", "debug");
//etc.
Jacob
  • 153
  • 5
0

You should use the Log Class

For exemple try this :

String TAG = myExemple;
Log.i(TAG, inputLine);

You'll find a more detailed explanation here

Kevin Gilles
  • 463
  • 1
  • 8
  • 23