Android Development java.lang.RuntimeException:Unable to start activity componentinfo{xxx}: Java.lang.NullPoi

Source: Internet
Author: User

Today, learning about Android development suddenly encountered this problem, looked at a lot of information, and the focus on the reasons for analysis.

Error message string: Java.lang.RuntimeException:Unable to start activity Componentinfo{com.first/com.first.game}: Java.lang.NullPointerException

This error is commonly found in Setcontentview (XXX) in the Activity OnCreate () method, and there are a number of reasons available on the web for about four important possible reasons:

Reason one: XXX error, if for r.layout.main then should be main.xml file in the label use error, the most common and compiler does not prompt error is android:name and Android:id both confused, Carefully check that the Main.xml label is all correct

Reason two: the Requestwindowfeature () method was used after the Setcontentview (view) method, and the following error prompts requestfeature to be used before setcontentview. You just need to put the Requestwindowfeature () method before the Setcontentview (view) method to resolve

Reason three: In addition to the OnCreate () method and not belonging to any one of the method bodies directly to a control FindByID (r.id.xx), it needs to be findbyid in a method and before the Setcontentview (view) method ( R.ID.XX) can be resolved

Reason four: Before Setcontentview (view) did not instantiate the view, only made a statement directly Setcontentview (view) caused, carefully check if the view is Setcontentview (view) can be resolved before it is invoked and instantiated within the method

Reason five: Because of a null pointer error exception, you should check whether something like Spinner or list has a value in it.


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.