When debugging code, we need to view the debugging information, so we need to use the android log class.
Common android. util. Log methods include:5Items:Log. V () Log. D () Log. I () log. W ()AndLog. E (). Corresponds to the first letterVerbose,Debug, info, warn, and error.
1. the debugging color of log. V isBlack, Any message will be output. Here v stands for verbose, which is usually used as log. V ("","");
2. The output color of log. D isBlueOnly the meaning of DEBUG debugging is output, but the upper-layer information is output, which can be selected through the logcat tag of ddms.
3. The output of log. I isGreenGenerally, the prompt message information does not output the information of log. V and log. D, but displays the information of I, W, and E.
4. log. W meansOrangeIt can be seen as a warning of warning. Generally, we need to optimize the android code and select it to output log. e information.
5. If log. e is red, you can think of error errors. Here, only red error messages are displayed. We need to carefully analyze these errors and view stack information.
Note: different printing methods are used with the (string tag, string MSG) parameter in a method. Tag indicates the tag of the printed information, and MSG indicates the information to be printed.
Below is a simple exampleLogdemo(Step by step ):
Step 1: Preparation (openLogcatWindows ).
StartEclipse, InWindow-> show ViewA dialog box is displayed. When we clickOKButton appears in the console windowLogcatWindows. For example:
Step 2: CreateAndroidProject, namedLogdemo.
Step 3:DesignUIInterface, we addButtonButtonLogLog information ).
Main. xmlThe Code is as follows:
<? XML version = "1.0" encoding = "UTF-8"?> <Br/> <linearlayout xmlns: Android = "http://schemas.android.com/apk/res/android" <br/> Android: Orientation = "vertical" <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "fill_parent" <br/> <textview <br/> Android: layout_width = "fill_parent" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "@ string/Hello" <br/> <button <br/> Android: id = "@ + ID/BT" <br/> Android: layout_width = "wrap_content" <br/> Android: layout_height = "wrap_content" <br/> Android: TEXT = "Presse me look log" <br/> </linearlayout>
Step 4: Design the main classLogdemo. JavaThe Code is as follows:
Public class logdemo extends activity {</P> <p> Private Static final string activity_tag = "logdemo"; <br/> private button Bt; <br/> Public void oncreate (bundle savedinstancestate) {<br/> super. oncreate (savedinstancestate); <br/> setcontentview (R. layout. main); <br/> // find the button resource through findviewbyid <br/> bt = (button) findviewbyid (R. id. BT); <br/> // Add Event Response <br/> BT. setonclicklistener (New button. onclicklistener () {<br/> @ override <br/> Public void onclick (view v) {<br/> log. V (logdemo. activity_tag, "this is verbose. "); <br/> log. D (logdemo. activity_tag, "this is debug. "); <br/> log. I (logdemo. activity_tag, "this is information"); <br/> log. W (logdemo. activity_tag, "this is warnning. "); <br/> log. E (logdemo. activity_tag, "this is error. "); <br/>}</P> <p >}); <br/>}</P> <p>}
Step
5: RunLogdemoProject, the effect is as follows:
When you click the button, the event is triggered. The following results are displayed in the logcat window:
This article from http://blog.csdn.net/Android_Tutor/archive/2009/12/26/5081713.aspx