Android Program debugging

Source: Internet
Author: User

1. Use the Log.d method to output debug log information.

The Log.d method is used to output debug fault log information, which has two overloaded forms, where the overloaded form syntax that developers often use is as follows:

 Public Static int d (string tag, string msg)
    • A tag:string string that identifies the log information, which is typically specified as the name of the class or activity that may appear debug.
    • A msg:string string that represents the string information to output.

The following instance, clicking the button in the Android interface will see the debug log information in the Logcat manager.

1. Modify the layout file Main.xml under the Res/layout directory under the new project, where you add a button component with the following main code:

<LinearLayoutxmlns:android= "Http://schemas.android.com/apk/res/android"Xmlns:tools= "Http://schemas.android.com/tools"android:orientation= "vertical"Android:layout_width= "Match_parent"Android:layout_height= "Match_parent"Android:paddingbottom= "@dimen/activity_vertical_margin"Android:paddingleft= "@dimen/activity_horizontal_margin"Android:paddingright= "@dimen/activity_horizontal_margin"Android:paddingtop= "@dimen/activity_vertical_margin"Tools:context= "Com.example.tiaoshi.MainActivity" >    <TextViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "@string/hello_world" />    <ButtonAndroid:id= "@+id/btn"Android:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:text= "Debug Log" /></LinearLayout>

2. Open the activity file, first obtain the button component in the layout file based on the ID, then set the Click Listener event for the component, and in the listener event, use the Log.d method to output the debug log information as follows:

Button BTN =NULL; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main);  This. btn = (Button) Findviewbyid (R.ID.BTN);//Get button ComponentBtn.setonclicklistener (NewOnclicklistener () {//Setting up Listener events@Override Public voidOnClick (View arg0) {LOG.D ("Debug", "Debug Log Information");//Output debug Log information            }                    }); }

3. The result is as shown

2. Output error messages using the LOG.E method

The LOG.E method is used to output error log information, which has two overloaded forms, where the overloaded form syntax that developers often use is as follows:

 Public Static int e (string tag, string msg)
    • A tag:string string that identifies the log information, which is typically specified as the name of the class or activity where the error may occur.
    • A msg:string string that represents the string information to output.

method as above.

3. Using the LOG.I method to output program log information

The LOG.I method is used to output the info program log information, which has two overloaded forms, where the overloaded form syntax that developers often use is as follows:

 Public Static int I (string tag, string msg)
    • A tag:string string that identifies the log information, which is typically specified as the name of the class or activity.
    • A msg:string string that represents the string information to output.
4. Output redundant log information using the LOG.V method

The LOG.V method is used to output verbose redundant log information, which has two overloaded forms, where the overloaded form syntax that developers often use is as follows:

 Public Static int V (string tag, string msg)
    • A tag:string string that identifies the log information, which is typically specified as the name of a class or activity that may appear redundant.
    • A msg:string string that represents the string information to output.
5. Output warning log information using the LOG.W method

The LOG.W method is used to output warn warning log information, which has 3 overloaded forms, where the overloaded form syntax that developers often use is as follows:

 Public Static int W (string tag, string msg)
    • A tag:string string that identifies the log information, which is typically specified as the name of the class or activity that may be warning.
    • A msg:string string that represents the string information to output.

Android Program debugging

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.