我之前看到过这个错误,但没有一个答案似乎解决了我的问题,所以我不确定是怎么回事。当它试图在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
我拥有所有构造函数并且没有看到任何其他问题,我缺少什么?
答案 0 :(得分:3)
尝试将DrawOnTop分离到同一个包中的另一个文件。