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

Source: Internet
Author: User

Android Development java.lang.RuntimeException:Unable to start activity componentinfo{xxx}: Java.lang.NullPointerException The cause and solution of error concentration

Today learning Android Development suddenly encountered this problem, consulted 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

will generally be inActivity onCreate ()in the method.Setcontentview (XXX)There are a number of reasons why this error occurred online, and there are about four important possible reasons:

Reason one:XXXthe error, if theR.layout.mainso it should be .Main.xmltags in the file using errors, the most common and the compiler does not prompt the error isAndroid:nameand theAndroid:idthe two are confused and examined carefullyMain.xmlthe labels are all correct

reason two: inSetcontentview (view)method is used after therequestwindowfeature()method, and you are prompted under this errorrequestfeaturemust be inSetcontentviewprior to use, just putrequestwindowfeature() method is placed in theSetcontentview (view) method can be resolved before

onCreate () and does not belong to any one method body directly to a control findById (R.id.xx setContentView (view) before method findbyid (r.id.xx) to resolve

reason four: inSetcontentview (view)no prior toViewis instantiated and is only declared and directlySetcontentview (view)The result is a careful examinationViewisSetcontentview (view)can be resolved before calling and instantiating within a method

Cause five: Because of a null pointer error exception, you should check whether something like Spinner or list has value exists

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

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.