Android:Crash: Binary XML file line : Error inflating class (using SurfaceView)

后端 未结 1 1795
刺人心
刺人心 2020-12-11 16:37

I\'m having android surfaceView and in that I\'m trying to add buttons to this. In the surfaceView canvas I draw something. And I have a thread class to keep drawing.

<
相关标签:
1条回答
  • 2020-12-11 16:53

    First, you must declare your view as a static type, to be able to be inflated it even when no instance of the holding class is available:

    public static class MySurfaceView extends SurfaceView 
        implements SurfaceHolder.Callback
    

    The line

    <com.androidsurfaceview.test.MySurfaceView
    

    in your layout xml suggests, that the MySurfaceView class is inside the com.androidsurfaceview.test package, and tries to inflate it from there, which is wrong.

    In your layout you should follow the package.class$innerclass form of declaration.

    BUT since the "$" is illegal character, you cannot write

    <com.androidsurfaceview.test$MySurfaceView
    

    so you must specify your view in the layout xml as follows:

    <view class="com.androidsurfaceview.test$MySurfaceView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"/>
    

    This way it will work.

    0 讨论(0)
提交回复
热议问题