user3185164
user3185164

Reputation: 3

Error inflating GLSurfaceView

I'm trying to set my GLSurfaceView on an xml layout along with other UI elements and keep getting error inflating class com.vi.cubo01.MyGLSurfaceView in the LogCat.

Here is the java code:

super.onCreate(savedInstanceState);

           mGLSurfaceView = (MyGLSurfaceView) findViewById(R.id.vistaGLSuperficie)
           setContentView(R.layout.activity_main);            
    }

    @Override
    protected void onResume() 
    {

            super.onResume();
            mGLSurfaceView = (MyGLSurfaceView) findViewById(R.id.vistaGLSuperficie);
            mGLSurfaceView.onResume();
    }

    @Override
    protected void onPause() 
    {
            super.onPause();
            mGLSurfaceView = (MyGLSurfaceView) findViewById(R.id.vistaGLSuperficie);
            mGLSurfaceView.onPause();
    }



    class MyGLSurfaceView extends GLSurfaceView {
        public MyGLSurfaceView(Context context) {
            super(context);
            setEGLContextClientVersion(2);
            setRenderer(new CustomRenderer());
        }
    }

and the xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<EditText
    android:id="@+id/editText1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10" >

    <requestFocus />
</EditText>

<EditText
    android:id="@+id/editText2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:ems="10"
    android:inputType="textMultiLine" />

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="0" />

<SeekBar
    android:id="@+id/seekBar1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

<com.vi.cubo01.MyGLSurfaceView
    android:id="@+id/vistaGLSuperficie"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     />

Upvotes: 0

Views: 2413

Answers (2)

Vasiliy Kulakov
Vasiliy Kulakov

Reputation: 5491

Kotlin version:

class MyGLSurfaceView(context: Context,
                          attributes: AttributeSet? = null): GLSurfaceView(context, attributes) {
// ...
}

Upvotes: 1

NigelK
NigelK

Reputation: 8455

If you are inflating from XML, you will need to include the (Context, AttributeSet) constructor in addition to the (Context) constructor that you already have. This is because that is the one that the layout inflator needs to call in order to process the attributes you have specified in the XML, e.g. layout_width and layout_height.

public MyGLSurfaceView(Context context, AttributeSet attrs) {
    super(context, attrs);
    setEGLContextClientVersion(2);
    setRenderer(new CustomRenderer());
}

Upvotes: 5

Related Questions