android.view.InflateException: Binary XML file line #0: Error inflating class <unknown> 解决办法

  项目跑成功了,打开后进入一个activity时出问题,崩溃,报错
这里写图片描述
  可以将问题定位在XML文件出了问题。
  出错误的地方大概率是下面几种情况,可以根据错误日志进行排查。

  1. 首先重构一下项目,rebuild project,看是否消失。
  2. 是否使用自定义的view,检查路径是否完整且正确。
  3. 检查资源文件是否引用错误。
  4. 检查自定义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 

  我的问题出在资源引用错误,第四条,接下来是我按照日志排查的过程。

//只是摘录了 Cause by
Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class <unknown>
Caused by: java.lang.reflect.InvocationTargetException
Caused by: android.content.res.Resources$NotFoundException: Drawable com.example.heartratedect:color/colorPrimary with resource ID #0x7f040028
Caused by: android.content.res.Resources$NotFoundException: Resource "com.example.heartratedect:color/colorPrimary" (7f040028) is not a Drawable (color or path): TypedValue{t=0x1/d=0x7f040028 a=-1 r=0x7f040028}

  第一个错误集中处并没有发现什么非常有用的信息,先向下面检索
这里写图片描述
  第二个错误提示处发现了和一开始的错误提示有区别,然后就需要打起精神了
这里写图片描述

  定位问题,出在color资源的引用上,是因为它并不是被需要的一个drawable类型。
  找到源文件中引用这个资源的代码,锁定出问题的地方,将这句话删掉后,问题解决

这里写图片描述

猜你喜欢

转载自blog.csdn.net/qunqunstyle99/article/details/81209875
今日推荐