Error inflating when extending a class

Error inflating when extending a class

Asked on December 20, 2018 in XML.
Add Comment


  • 3 Answer(s)

    Error inflating when extending a class:

         Here provided a constructor for the case of one parameter ‘context’ when provided a constructor for the two parameter ‘Context, AttributeSet’ case. Give the constructor(s) public access if it needed,

    public class GhostSurfaceCameraView extends SurfaceView implements SurfaceHolder.Callback {
      SurfaceHolder mHolder;
      Camera mCamera;
     
      public GhostSurfaceCameraView(Context context)
      {
        super(context);
        init();
      }
      public GhostSurfaceCameraView(Context context, AttributeSet attrs)
      {
        super(context, attrs);
        init();
      }
      public GhostSurfaceCameraView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
      }
    
    Answered on December 20, 2018.
    Add Comment

    Here is the solution:

         The constructors both are not required, only the ViewClassName(Context context, AttributeSet attrs ) constructor is enough. It maybe due to the fact that we are adding the custom View class in the XML file, and setting several attributes to it in the XML, which needs to be processed at the time of instantiation.

    Answered on December 20, 2018.
    Add Comment

    Initialize the process:

         The “Error inflating class” message may miscopy the full package name where it is specified in XML below.Opening the layout XML file in the Eclipse XML editor should highlight this,

    <com.alpenglow.androcap.GhostSurfaceCameraView android:id="@+id/ghostview_cameraview"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"/>
    

     

    Answered on December 20, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.