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.