A summary of the easy error point of Android development

Source: Internet
Author: User
Tags exception handling sqlite sqlite database

For Android programmers, there are a lot of places where we need to be aware of Android apps, and here's where Android123 by browsing through most of the source code.

  I. cursor of the database

  For the Android SQLite database encapsulated query return object cursor It's more error prone to have

1. Cursor return may be null.

If query returns an empty cursor object, any method that executes cursor must have a null pointer exception, which is not noticed by 40% of the Android code.

2. Cursor returned to 0.

We just judge not to be empty yet, if the object of cursor is 0, execute Movetofirst (); This approach is more embarrassing, the Android development network is particularly prompted attention.

3. Movetofirst () is not executed while traversing the cursor, so that the position of the cursor is indeterminate.

4. Cursor after use to manually shut down, Cursor.close () This method do not forget.

5. The types of cursor, such as Getint and Getlong, are always remembered for the conversion, since both the Boolean and long types are sqlite integers in SQLite.

  Second, the new service, activity is not registered in the Androidmanifest.xml, for the activity is good to say, if the service at the same time service use of package Name does not differ from the package name of the main program remember to manually write the relative package name

  Third, Parcelable the internal class exception handling when used, for example, when the bitmap object is stored internally, the problem arises if the bitmap object is empty.

Related Article

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.