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