Android (Java) Learning Note 152:android Runtime exception "Binary XML file Line #: Error inflating Class"

Source: Internet
Author: User

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 out. .....

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, this time you have to layout 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, with Mypackage.mytestview to make a 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 (Java) Learning Note 152:android Runtime exception "Binary XML file Line #: Error inflating Class"

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.