有时候一个很简单的xml布局文件,运行却抛出以下异常:

07-25 10:40:50.966: D/AndroidRuntime(31570): Shutting down VM
07-25 10:40:50.966: W/dalvikvm(31570): threadid=1: thread exiting with uncaught exception (group=0x42441700)
07-25 10:40:50.976: E/AndroidRuntime(31570): FATAL EXCEPTION: main
07-25 10:40:50.976: E/AndroidRuntime(31570): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.moveball/com.example.moveball.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class com.example.moveball.DrawView
07-25 10:40:50.976: E/AndroidRuntime(31570): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2308)
07-25 10:40:50.976: E/AndroidRuntime(31570): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2362)
07-25 10:40:50.976: E/AndroidRuntime(31570): at android.app.ActivityThread.access$700(ActivityThread.java:168)
07-25 10:40:50.976: E/AndroidRuntime(31570): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1329)

出现这种异常,一般是与相应的xml的标签和属性的命名、定义有关。

有时候很小的错误就会产生这种问题,这种小错误一般很难检查,所以在写代码的时候就要有所注意,免得之后检查起来麻烦。

比如:控件EditText写成了TextView等小问题

又如:没有找到资源文件。

提示:可以参考我的另外一篇文章《Android资源文件夹及资源文件的详细介绍》

一般看看res/下面的资源文件,比如全放在drawable-mdpi/目录下,,将drawable-mdpi/下的资源文件拷贝一份到drawable-ldpi/目录下,还是报错误,再拷贝一份到drawable-hdpi/目录下,问题解决。

要经常怀疑寻找的位置资源文件不存在。

一般在res/下建一目录drawable/,将drawable-mdpi/下所有的资源文件都拷贝到drawable/下即可。

这些类似的等等资源文件的错误需要注意。

总结一下xml文件经常容易犯的低级错误:

1. 控件名称不能写错

2.名称的大小写要区分,如EditText与editText是完全不一样的

3.标签一定是成对出现的,尤其是嵌套布局

4.属性前面一般要加android:

5.id比较特殊,应该是@+id ,其它的直接加@即可,如@string

6.drawable中引用的图片资源不存在或名称大小写有误

此外,出现这种异常还可能与自定义的View类有关,需要增加一个带属性的构造函数

抛出异常时的main.xml与自定义View类相关代码如下:

activity_main.xml:

<span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"android:layout_height="match_parent"tools:context=".MainActivity" ><com.example.moveball.DrawViewandroid:id="@+id/drawView"android:layout_width="match_parent"android:layout_height="match_parent" ></com.example.moveball.DrawView></RelativeLayout></span>

继承View的类的自定义View:

<span style="font-size:14px;">public class DrawView extends View{private float circleX = 40;private float circleY = 50;private float circleR = 15;// 构造方法public DrawView(Context context){super(context);}// 重写ondraw方法   下面代码省略了...</span>

对于此异常,如下进行修改:添加View类的另一个构造方法即可解决问题!

<span style="font-size:14px;">public class DrawView extends View{private float circleX = 40;private float circleY = 50;private float circleR = 15;// 构造方法public DrawView(Context context,AttributeSet attrs){super(context,attrs);}</span>

总之抛出这种异常的原因有可能是必须实现的构造器没有实现:

须实现三个构造函数
    public GalleryFlow(Context context) {
            super(context);
    }

public GalleryFlow(Context context, AttributeSet attrs) {
            super(context, attrs);
    }

public GalleryFlow(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
    }


android.view.inflateexception binary xml file line 异常的解决方法相关推荐

  1. Android.View.InflateException: Binary XML File Line #异常的解决

    这个运行错误,主要出现在安卓系统5.0一下手机系统.在5.0以上手机系统,不会出现这个错误 错误如下:在引入自定义VIEW时报错 原因:资源文件shape_new_message.xml在drawab ...

  2. Android运行时候报错:android.view.InflateException: Binary XML file line #19: Binary XML file lin

    Android运行时候报错:android.view.InflateException: Binary XML file line #19: Binary XML file lin 这个问题自己大致在 ...

  3. android.view.InflateException: Binary XML file line #7: Binary XML file line #7

    错误如下 11-21 08:19:44.040 3608-3608/com.leon.oldrecyclerview E/AndroidRuntime: FATAL EXCEPTION: main   ...

  4. 报错android.view.InflateException: Binary XML file line #11: Attempt to invoke virtual method 'boolean

    出现这种问题,打开Android monitor的调试信息发现是 android.view.InflateException: Binary XML file line #11: Attempt to ...

  5. Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class lzl.edu.c

    在自定义view中常常会出现这么一个错误 Caused by: android.view.InflateException: Binary XML file line #12: Error infla ...

  6. android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating

    android.view.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating cla ...

  7. Android stuido 解决Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file

    Android stuido 解决Caused by: android.view.InflateException: Binary XML file line #8: Binary XML file ...

  8. 运行安卓程序报错android.view.InflateException: Binary XML file line #11: Error inflating class ImageView

    运行安卓程序报错android.view.InflateException: Binary XML file line #11: Error inflating class ImageView 先上代 ...

  9. Android编程:解决异常“android.view.InflateException: Binary XML file line # : Error inflating class”

    我一般都是在1和4 遇到,记录一下. 今天写程序发现一个问题,就是XML中报出Android.view.InflateException异常,可能的原因有: 1.XML中使用到得组件名称是否书写正确( ...

最新文章

  1. Linux学习(五)---开机、重启和用户登录注销
  2. linux上安装配置vsftpd
  3. php使用fopen乱码,php下fopen中文文件名乱码怎么办?
  4. 配置虚拟目录的方式(Linux下/windows下)
  5. C51 printf修改如何能打印到不同的设备呢?
  6. 几道题帮你搞定数据选择器
  7. 前端学习(3309):redux项目创建和概况
  8. Python数模笔记-模拟退火算法(2)约束条件的处理
  9. Java内存泄漏的介绍
  10. 2021-05-17 吾日三省吾身
  11. c语言 愚人节题目,愚人节整人题目大全
  12. 批量图片下载器(整站下载)
  13. Linux 异常:The following signatures couldn‘t be verified because the public key is not available
  14. 回收戴尔R740 R740XD - CSDN
  15. android 第三方相册,相册选择图片
  16. 上海财经应用统计考python_19上海财经大学应用统计专硕考研初试复试帖
  17. 模拟PWM波的自适应取阈值算法
  18. 【Codeforces 1083A】The Fair Nut and the Best Path
  19. Linux查看实时网速
  20. 阿里云大学考试Java中级题目及解析-java中级

热门文章

  1. 基于STM32F103C8T6片内Flash的音频播放(DAC通道)
  2. python字符串阿拉伯数字与中文转换
  3. python-openCV识别银行卡号,车牌同理,代码直接可用
  4. 模拟登录淘宝,清空购物车
  5. 【OS】NMON的简介和使用
  6. wps如何取消自动编号?试试这3种方法
  7. 搜狗搜索蜘蛛解析讲解
  8. php中autofocus,HTML5中的autofocus(自动聚焦)属性介绍
  9. python中英文混输对不齐_python中英文混合字符串对齐输出
  10. c语言编写程序能够随机出题,用C语言写一个 小学生口算出题系统