android运行时异常:Binary XML file line # : Error inflating class
Posted 炒鸡蛋
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android运行时异常:Binary XML file line # : Error inflating class相关的知识,希望对你有一定的参考价值。
自定义View时出现的,搞了好半天终于搞好了。
继承View时要要实现它所有的构造函数。
如:
1 public class hongdian extends View { 2 float x=40; 3 float y=50; 4 Paint p = new Paint(); 5 //要实现的构造 6 public hongdian(Context context) { 7 super(context); 8 } 9 //要实现的构造函数 10 public hongdian(Context context, @Nullable AttributeSet attrs) { 11 super(context, attrs); 12 } 13 //要实现的构造函数 14 public hongdian(Context context, @Nullable AttributeSet attrs, int defStyleAttr) { 15 super(context, attrs, defStyleAttr); 16 } 17 //要实现的构造函数 18 public hongdian(Context context, @Nullable AttributeSet attrs, int defStyleAttr, int defStyleRes) { 19 super(context, attrs, defStyleAttr, defStyleRes); 20 } 21 22 @Override 23 protected void onDraw(Canvas canvas) { 24 super.onDraw(canvas); 25 p.setColor(Color.BLACK); 26 canvas.drawCircle(x,y,15,p); 27 } 28 29 @Override 30 public boolean onTouchEvent(MotionEvent event) { 31 x = event.getX(); 32 y = event.getY(); 33 this.invalidate(); 34 return true; 35 } 36 }
以上是关于android运行时异常:Binary XML file line # : Error inflating class的主要内容,如果未能解决你的问题,请参考以下文章
android.view.InflateException: Binary XML file line #95: Error inflating class(out of memory) 。异常(示例
android.view.InflateException: Binary XML file line #16: Error&nbs
android.view.InflateException: Binary XML file line #7: Error inflating class
Android android.view.InflateException Binary XML 文件第 16 行:膨胀类片段时出错
android.view.InflateException: Binary XML file line #7: Error inflating class Toolbar
Caused by: android.view.InflateException: Binary XML file line #12: Error inflating class android.su