Binary XML file #33 in com.xxx.xxx/activity_main:Error inflating class view

从源码上分析一下这个错误的原因:

先看下这个错误抛出异常的代码
final InflateException ie = new InflateException(attrs.getPositionDescription()+ ": Error inflating class " + name, e);

attrs.getPositionDescription()的解释如下:
Returns a description of the current position of the attribute set.For instance, if the attribute set is loaded from an XML document,the position description could indicate the current line number.
return A string representation of the current position in the set,
may be null.

情况分析:
这个错误的大部分情况会在res文件夹下抛出,加载布局文件一般是setContentView或者inflate ,都会调用inflate方法

public View inflate(@LayoutRes int resource, @Nullable ViewGroup root) {return inflate(resource, root, root != null);
}

inflate中会调用私有的inflate方法,这个方法中会加载资源,并获得XmlResourceParser,一个xml解析器

public View inflate(@LayoutRes int resource, @Nullable ViewGroup root, boolean attachToRoot) {final Resources res = getContext().getResources();if (DEBUG) {Log.d(TAG, "INFLATING from resource: \"" + res.getResourceName(resource) + "\" ("+ Integer.toHexString(resource) + ")");}final XmlResourceParser parser = res.getLayout(resource);try {return inflate(parser, root, attachToRoot);} finally {parser.close();}}

接下来在inflate方法中会调用

final View temp = createViewFromTag(root, name, inflaterContext, attrs);

最终createViewFromTag方法,可以看到是在加载一些属性或者资源文件的时候可能抛出异常

* Creates a view from a tag name using the supplied attribute set.
* <p>
* <strong>Note:</strong> Default visibility so the BridgeInflater can
* override it.
*
* @param parent the parent view, used to inflate layout params
* @param name the name of the XML tag used to define the view
* @param context the inflation context for the view, typically the
*                {@code parent} or base layout inflater context
* @param attrs the attribute set for the XML tag used to define the view
* @param ignoreThemeAttr {@code true} to ignore the {@code android:theme}
*                        attribute (if set) for the view being inflated,
*                        {@code false} otherwiseView createViewFromTag(View parent, String name, Context context, AttributeSet attrs,boolean ignoreThemeAttr) {if (name.equals("view")) {name = attrs.getAttributeValue(null, "class");}// Apply a theme wrapper, if allowed and one is specified.if (!ignoreThemeAttr) {final TypedArray ta = context.obtainStyledAttributes(attrs, ATTRS_THEME);final int themeResId = ta.getResourceId(0, 0);if (themeResId != 0) {context = new ContextThemeWrapper(context, themeResId);}ta.recycle();}if (name.equals(TAG_1995)) {// Let's party like it's 1995!return new BlinkLayout(context, attrs);}try {View view;if (mFactory2 != null) {view = mFactory2.onCreateView(parent, name, context, attrs);} else if (mFactory != null) {view = mFactory.onCreateView(name, context, attrs);} else {view = null;}if (view == null && mPrivateFactory != null) {view = mPrivateFactory.onCreateView(parent, name, context, attrs);}if (view == null) {final Object lastContext = mConstructorArgs[0];mConstructorArgs[0] = context;try {if (-1 == name.indexOf('.')) {view = onCreateView(parent, name, attrs);} else {view = createView(name, null, attrs);}} finally {mConstructorArgs[0] = lastContext;}}return view;} catch (InflateException e) {throw e;} catch (ClassNotFoundException e) {final InflateException ie = new InflateException(attrs.getPositionDescription()+ ": Error inflating class " + name, e);ie.setStackTrace(EMPTY_STACK_TRACE);throw ie;} catch (Exception e) {final InflateException ie = new InflateException(attrs.getPositionDescription()+ ": Error inflating class " + name, e);ie.setStackTrace(EMPTY_STACK_TRACE);throw ie;}}

所以这个遇到这个错误还是要好好检查你的属性或者资源文件
补充
setContentView方法调用inflate

public void setContentView(int resId) {this.ensureSubDecor();ViewGroup contentParent = (ViewGroup)this.mSubDecor.findViewById(16908290);contentParent.removeAllViews();LayoutInflater.from(this.mContext).inflate(resId, contentParent);this.mOriginalWindowCallback.onContentChanged();
}

Binary XML file line : Error inflating class 错误分析相关推荐

  1. Android 异常 “Binary XML file line # : Error inflating class”

    自己的项目在Pad上一直运行正常,可是当运行在手机上时在一个Inflater.inflater()解析布局时出现了运行时异常" Binary XML file line # : Error ...

  2. android error inflating 自定义控件,解决Android 异常 “Binary XML file line # : Error inflating class”...

    自己的项目在5.0及以上的手机山一直运行正常,可是当运行在低版本手机上时在一个Inflater.inflater()解析布局时出现了运行时异常" Binary XML file line # ...

  3. Android 运行时异常 Binary XML file line # : Error inflating class

    今天在做一个二维码扫描的项目的时候出现了一个错误: android.view.InflateException: Binary XML file line #12: Error inflating c ...

  4. Binary XML file line : Error inflating class unknown(记录一个很内伤的错误)

    异常信息指出了在51行,我的51行是这个 <ImageView         android:id="@+id/iv_information_commend"       ...

  5. 关于编译时错误Binary XML file line #:error inflating imageview

    今天在提交项目之后 客户反馈项目崩溃.但是在我们自己的手机和测试手机运行并没有问题..当我切换到一个版本更低的手机崩溃报了以下错误Binary XML file line 44:error infla ...

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

    转自:http://blog.csdn.net/huangxiaohu_coder/article/details/8497286 在原生Android下编译APK,编译没有问题,但是在运行的时候经常 ...

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

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

  8. Android运行时异常“Binary XML file line # : Error inflat

    2019独角兽企业重金招聘Python工程师标准>>> 在原生Android下编译APK,编译没有问题,但是在运行的时候经常出现如标题所描述的异常,然后整个程序Crash掉..... ...

  9. Binary XML file line #8: Error inflating class android.support.v7.widget.RecyclerView

    今天创建了一个 demo ,然后就是复制RecyclerView 过去, 到最后完成运行的时候发现 系统奔溃了, 然后 提示 Binary XML file line #8: Error inflat ...

最新文章

  1. python 过滤出某后缀名文件
  2. 漫画:臭长臭长的高频贪心面试题
  3. Flutter开发之爬坑集合(五)
  4. android:versionCode 跟 android:versionName
  5. 关于python语言、下列说法不正确的是-关于 Python语言,哪个说法是不正确的?
  6. python矩阵相加_【python矩阵相加怎么做,这可是证明python功能的大好机会】- 环球网校...
  7. 2018年云栖社区展望(建设性意见非BUG)
  8. h5获取http请求头_React 前端获取http请求头信息
  9. 字典使用与内部实现原理
  10. RepPoints(本质是可变形卷积DCN)再理解
  11. 最大公约数(Greatest Common Divisor)
  12. svg操纵方案 基于 D3 还是 angular?
  13. 目前阶段的任务及计划
  14. 在ASP中常见的错误80004005信息和解决办法
  15. 一步一步解决“不能上网”
  16. 如何做好软件项目管理工作?
  17. 均匀分布方差的计算方法
  18. golang:goredis库pipeline使用方式
  19. input()函数的简单介绍
  20. 《A Survey on Evolutionary Computation for Complex Continuous Optimization》笔记

热门文章

  1. 淘宝天猫分进合击打造新零售基座 年轻一代管理者出任总裁
  2. python调用yolov3模型_yolo3-keras的源码,可以用于训练自己的模型yolov3以及yolov3-tiny...
  3. 微商怎么用快手引流?因为短视频的存在形式非常符合人们现在快节奏的生活
  4. linux sftp ssh端口分开,Linux SSH和SFTP服务分离
  5. .NET处理VUE OPTIONS请求问题
  6. dos命令行设置网络优先级_笔记本网络连接图标不见了怎么办?
  7. 七、JavaScript新特性
  8. Java面试复习总结(Mysql篇9)——MySQL里的那些日志
  9. console彩蛋——藏在console的招聘信息
  10. 洛谷P1055 ISBN 号码 —— JAVA