我之前看到过这个错误,但似乎没有一个答案能解决我的问题,所以我不确定发生了什么。当它试图在 xml 中膨胀我的类时它失败了。
XML:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#EEE"
>
<android.view.SurfaceView
android:id="@+id/preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</android.view.SurfaceView>
<com.commonsware.android.picture.PictureDemo.DrawOnTop
android:id="@+id/grid"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</com.commonsware.android.picture.PictureDemo.DrawOnTop>
</FrameLayout>
班级:
class DrawOnTop extends View
{
public DrawOnTop(Context context)
{
super(context);
}
public DrawOnTop(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public DrawOnTop(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
@Override
protected void onDraw(Canvas canvas)
{
Paint paint = new Paint();
paint.setStyle(Paint.Style.STROKE);
paint.setColor(Color.BLACK);
canvas.drawText("Test Text", 10, 10, paint);
canvas.drawBitmap(bitmap, 0, 0, null);
super.onDraw(canvas);
}
}
错误:
02-11 16:06:25.456: E/AndroidRuntime(11717): Caused by: android.view.InflateException: Binary XML file line #14: Error inflating class com.commonsware.android.picture.PictureDemo.DrawOnTop
我有所有的构造函数,没有看到任何其他问题,我错过了什么?