How can I inflate glsurfaceview in android's layout xml

I am trying to put a GLSurfaceView in a xml layout, but when I try to do it my application keeps closing automatically. I think the problem is in layout/activity_main.xml, because I don't know the name of the tag for glsurgaceview. This is my code. Can you please tell me what is wrong with my code. Thanks for your help.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
     tools:context=".AnimationActivity">

    <TextView
        android:id="@+id/angolo"
        android:layout_width="wrap_content"
android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="135dp"
        android:text="Angolo:"
        android:textAppearance="?android:attr/textAppearanceMedium" />

    <view
        class="rugani.tesi.animazione3d.AnimationActivity$MyGLSurfaceView" 
        android:id="@+id/myglsurfaceView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />

</RelativeLayout>

This is myglsurfaceview :

protected void onCreate(Bundle savedInstanceState) {

  Logger.log("onCreate");

  super.onCreate(savedInstanceState);
  getActionBar().setDisplayHomeAsUpEnabled(true);


  /*
  mGLView = new GLSurfaceView(getApplication());
  mGLView.setEGLContextClientVersion(2);
  mGLView.setEGLConfigChooser(new AAConfigChooser(mGLView));
  mGLView.setRenderer(renderer); 
  setContentView(mGLView);
  */
  //mGLView = new MyGLSurfaceView(getApplication());
  //setContentView(mGLView);

  setContentView(R.layout.activity_main);
  mGLView = (MyGLSurfaceView) findViewById(R.id.graphics_glsurfaceview);

  pluto=(MyApplication)this.getApplication();
  mBoundService=pluto.getObj();
 }

and this is my oncreate()

private MyGLSurfaceView mGLView; 
private MyGLRenderer renderer;
protected void onCreate(Bundle savedInstanceState) {

  Logger.log("onCreate");

  super.onCreate(savedInstanceState);
  getActionBar().setDisplayHomeAsUpEnabled(true);


  /*
  mGLView = new GLSurfaceView(getApplication());
  mGLView.setEGLContextClientVersion(2);
  mGLView.setEGLConfigChooser(new AAConfigChooser(mGLView));
  mGLView.setRenderer(renderer); 
  setContentView(mGLView);
  */
  //mGLView = new MyGLSurfaceView(getApplication());
  //setContentView(mGLView);

  setContentView(R.layout.activity_main);
  mGLView = (MyGLSurfaceView) findViewById(R.id.graphics_glsurfaceview);

 }

this is the logcat:

09-18 10:52:17.665: E/ActivityThread(30263): Failed to inflate 09-18 10:52:17.665: E/ActivityThread(30263): android.view.InflateException: Binary XML file line #11: Error inflating class rugani.tesi.animazione3d.AnimationActivity.MyGLSurfaceView 09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:708) 09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.rInflate(LayoutInflater.java:756) 09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.inflate(LayoutInflater.java:492) 09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 09-18 10:52:17.665: E/ActivityThread(30263): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:344) 09-18 10:52:17.665: E/ActivityThread(30263): at android.app.Activity.setContentView(Activity.java:2127) 09-18 10:52:17.665: E/ActivityThread(30263): at rugani.tesi.animazione3d.AnimationActivity.onCreate(AnimationActivity.java:73) 09-18 10:52:17.665: E/ActivityThread(30263): at android.app.Activity.performCreate(Activity.java:6020) 09-18 10:52:17.665: E/ActivityThread(30263): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087) 09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2181) 09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2276) 09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread.access$800(ActivityThread.java:144) 09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1205) 09-18 10:52:17.665: E/ActivityThread(30263): at android.os.Handler.dispatchMessage(Handler.java:102) 09-18 10:52:17.665: E/ActivityThread(30263): at android.os.Looper.loop(Looper.java:136) 09-18 10:52:17.665: E/ActivityThread(30263): at android.app.ActivityThread.main(ActivityThread.java:5151) 09-18 10:52:17.665: E/ActivityThread(30263): at java.lang.reflect.Method.invokeNative(Native Method) 09-18 10:52:17.665: E/ActivityThread(30263): at java.lang.reflect.Method.invoke(Method.java:515) 09-18 10:52:17.665: E/ActivityThread(30263): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:796) 09-18 10:52:17.665: E/ActivityThread(30263): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:612) 09-18 10:52:17.665: E/ActivityThread(30263): at dalvik.system.NativeStart.main(Native Method) 09-18 10:52:17.665: E/ActivityThread(30263): Caused by: java.lang.ClassNotFoundException: Didn't find class "rugani.tesi.animazione3d.AnimationActivity.MyGLSurfaceView" on path: DexPathList[[zip file "/data/app/rugani.tesi.animazione3d-1.apk"],nativeLibraryDirectories=[/data/app-lib/rugani.tesi.animazione3d-1, /vendor/lib, /system/lib]] 09-18 10:52:17.665: E/ActivityThread(30263): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) 09-18 10:52:17.665: E/ActivityThread(30263): at java.lang.ClassLoader.loadClass(ClassLoader.java:497) 09-18 10:52:17.665: E/ActivityThread(30263): at java.lang.ClassLoader.loadClass(ClassLoader.java:457) 09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.createView(LayoutInflater.java:559) 09-18 10:52:17.665: E/ActivityThread(30263): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697) 09-18 10:52:17.665: E/ActivityThread(30263): ... 21 more

EDIT : I have updated this post with the new xml layout and with the error logcat

Upvotes: 0

Views: 2102

Answers (1)

Bill
Bill

Reputation: 1268

you need implements proper constructor

MyGLSurfaceView(Context context, AttributeSet attrs)

you can refer Using GLSurfaceView class with android xml layouts or Android glSurfaceView with overlay using XML/Java

Upvotes: 1

Related Questions