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

Source: Internet
Author: User

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

will generally be in Activity 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 fileusing 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 () method, and does not belong to any one method body directly to a control setcontentview (view) Span style= "margin:0px; padding:0px; font-size:9pt; Font-family: "The song Body" method before the

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 my app.

In the native Android to compile the APK, compile no problem, but at run time often appear as described in the title of the exception, and then the whole program crash off ...

I have encountered this problem often because of the modification of the resource files caused by, roughly the following several ways to solve:

1. referencing a class name problem : Customizing a view to use in a layout file, assuming that his package is named MyPackage, the class name is Mytestview, and this is when you lay out the XML as a layout element, you must use the full path name, That is, the package name plus the class name to refer to, using Mypackage.mytestview to reference.

2. constructor problem : To customize a view, you must derive the three constructors that implement the base class View

View (context context)//simple constructor to use where creating a View from code

View (context context, AttributeSet Attrs)//constructor that's called when inflating a view from XML

View (context context, AttributeSet attrs, int defstyle)//perform inflation from XML and apply a class-specific base s Tyle

From the introduction of the document, the second and third constructors have to be implemented for XML, and these three constructors should be used to instantiate a view object in different contexts.

3. the compiled intermediate file is not clean: The third is that you compile the original system code in the compilation environment after the APK, especially the modification of the XML, the title of the phenomenon, this time you just need to delete the out directory compiled in the generated intermediate folder can be (the specific name is not clear: During the compilation process, the system will print out that location, through the serial port to see it, .../out/....../..../classes.dex, you follow this path forward to your app's project name that layer folder), delete and re-make is OK.

4. resource file not found : I used to add live wallpaper in 2.3 of the native system, live wallpaper run up on this anomaly, and then crash, that was because I could not find drawable resource files, then I put drawable hdpi or nodpi folder picture resources are copied to drawble, the problem solution (It was not understood at the time that the system would choose to load resources under different drawable folders depending on the resolution, why it must be put into drawable).


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.