Displaying More string on Logcat

前端 未结 6 931
长发绾君心
长发绾君心 2020-12-04 18:10

I am currently working on an android App that uses \'JSON\' as response from server. Usually I work on the JSON response. But now I have a problem with logcat, if the JSON

6条回答
  •  时光取名叫无心
    2020-12-04 18:25

    In general if you want to get output into Logcat you should use the "Log" command.

    An example:

    Log.d(TAG,"OUTPUT"):
    

    d = debug
    TAG = a string you define, gets displayed in Logcat in the column before the "normal" output
    OUTPUT = stuff u want to get printed

    Log is a logging class you can use to print out messages to the logcat. You can read messages in real time if you run logcat on DDMS (covered next). Common logging methods include: v(String, String) (verbose), d(String, String) (debug), i(String, String) (information), w(String, String) (warning) and e(String, String) (error).

    For further information:

    http://developer.android.com/guide/developing/debug-tasks.html

    EDIT:

    What I ment before is, in order to test some things with outputs you shouldn't use:

    System.out.println("JSON stuff");
    

    Instead of using this you should use in your code:

    // Values just as example
    private static void string TAG = "+++JSON+++";
    ...
    Log.d(TAG,"JSON stuff in here");
    ...
    

    It will get displayed in Logcat. I don't exactly know why, but it't the better way. Like this you also could display an error message:

    Log.e(...);
    

    It will change the color of your output in Logcat, so you may see it better if e.g. an error occurrs.

提交回复
热议问题