jgelderloos
jgelderloos

Reputation: 388

error inflating class, custom view

I have seen this error posted before but none of the answers seem to fix my problem so I am not really sure what is going on. It is failing when it tries to inflate my class in the 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:

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); 
      } 
  } 

Error:

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

I have all the constructors and dont see any other problem, what am I missing?

Upvotes: 2

Views: 5882

Answers (1)

jtt
jtt

Reputation: 13541

Try separating DrawOnTop to another file within the same package.

Upvotes: 3

Related Questions