Android运行时异常“Binary XML file line # : Error inflating class”

简介:

http://blog.csdn.net/huangxiaohu_coder/article/details/8497286

 

在原生Android下编译APK,编译没有问题,但是在运行的时候经常出现如标题所描述的异常,然后整个程序Crash掉......

    我遇到该问题常常都是因为修改了资源文件所引起,大致有以下几种方式来解决:

    1. 引用类名问题:自定义了一个View,将他用于布局文件中,假设他的包名叫MyPackage,类名叫MyTestView,这个时候你在XML作为布局元素来布局的话,必须使用完整路径名,也就是包名加类名来引用,用MyPackage.MyTestView来进行引用。

    2.构造函数问题:自定义一个View,必须派生实现基类View的三个构造函数

    View(Context context)     //Simple constructor to use when creating a view from code

    View(Context context, AttributeSet attrs)     //Constructor that is called when inflating a view from XML

    View(Context context, AttributeSet attrs, int defStyle)     //Perform inflation from XML and apply a class-specific base style

    从文档上的介绍来看,第二个和第三个构造函数对于XML这种引用方式是必须实现的,这三个构造函数应该是在不同的应用场合来实例化一个View对象。

    3.编译的中间文件没有清理干净:第三种就是你在原生系统代码的编译环境下编译APK之后,特别是修改了XML,出现标题所述现象,这个时候你只需要删除out目录下编译生成的中间文件夹即可(具体名字记不清了:在编译过程中,系统会将那个位置打印出来,通过串口来看吧,.../out/....../..../classes.dex,你循着这个路径往前推到你的应用的project名字那一层文件夹),删除再重新make就OK了。

或者重新拉代码

 

 

    4.找不到资源文件:我原来在2.3的原生系统增加动态壁纸的时候,动态壁纸一跑起来就出这个异常,然后crash,当时就是因为找不到drawable的资源文件,于是当时我把drawable的hdpi或nodpi等文件夹的图片资源都拷贝一份到drawble下,问题解决(当时一直不明白系统会根据分辨率来选择加载不同drawable下文件夹的资源,为什么这里必须放入drawable中)。

分类:  android solve

本文转自wanqi博客园博客,原文链接:http://www.cnblogs.com/wanqieddy/p/4990608.html,如需转载请自行联系原作者


相关文章
|
26天前
|
Android开发 开发者
Error:Could not find com.android.support:appcompat-v7:27.0.2.
Error:Could not find com.android.support:appcompat-v7:27.0.2.
16 0
|
2月前
|
Android开发
【Bug】Android resource linking failed和error: failed linking references.
【Bug】Android resource linking failed和error: failed linking references.
|
16天前
|
Android开发 开发者
安卓投屏神器 Scrcpy安 报错ERROR: Could not find any ADB device
使用Scrcpy安卓投屏工具时遇到报错,问题根源是未开启开发者模式。解决步骤:进入设置,点击【关于手机】→连续点击版本号激活开发者模式,然后在【系统设置】→【开发者选项】中开启USB调试。参照此方法后可正常执行。Scrcpy软件下载链接和GitHub页面也已提供。
26 1
|
27天前
解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
解决Error:All flavors must now belong to a named flavor dimension. Learn more at https://d.android.com
22 5
|
8月前
|
XML Java Android开发
#4,Android Studio Android程序结构 工程目录介绍 文件作用 运行配置文件AndroidManifest.xml
#4,Android Studio Android程序结构 工程目录介绍 文件作用 运行配置文件AndroidManifest.xml
|
8月前
|
XML Android开发 数据格式
Android Binary XML file line #50: Error inflating class androidx.cardview.widget.CardView 错误
Android Binary XML file line #50: Error inflating class androidx.cardview.widget.CardView 错误
52 0
|
Java 开发工具 Android开发
Android Studio运行报错:无法访问XXX......请删除该文件或确保该文件位于正确的类路径子目录中
今天运行一个项目发现运行不起来了,报错 错误: 无法访问XXX 错误的类文件: C:\Users\xxx\.gradle\caches\transforms-2\files-2.1\xxx\xxx(xxx/xxx/xxx.class) 错误的 RuntimeInvisibleParameterAnnotations 属性: xxxx 请删除该文件或确保该文件位于正确的类路径子目录中。
1035 0
|
Android开发 Kotlin
【错误记录】Android Studio 运行报错 ( There is not enough memory to perform the requested operation. )
【错误记录】Android Studio 运行报错 ( There is not enough memory to perform the requested operation. )
569 0
【错误记录】Android Studio 运行报错 ( There is not enough memory to perform the requested operation. )
|
4天前
|
Linux 编译器 Android开发
FFmpeg开发笔记(九)Linux交叉编译Android的x265库
在Linux环境下,本文指导如何交叉编译x265的so库以适应Android。首先,需安装cmake和下载android-ndk-r21e。接着,下载x265源码,修改crosscompile.cmake的编译器设置。配置x265源码,使用指定的NDK路径,并在配置界面修改相关选项。随后,修改编译规则,编译并安装x265,调整pc描述文件并更新PKG_CONFIG_PATH。最后,修改FFmpeg配置脚本启用x265支持,编译安装FFmpeg,将生成的so文件导入Android工程,调整gradle配置以确保顺利运行。
24 1
FFmpeg开发笔记(九)Linux交叉编译Android的x265库
|
26天前
|
Java Android开发
Android 开发获取通知栏权限时会出现两个应用图标
Android 开发获取通知栏权限时会出现两个应用图标
12 0