Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid OpenGL extending GLSurfaceView null pointer exceptions
    text
    copied!<p>I am trying to create a simple 3-D app for android that will have an additional view layered on top of the OpenGL view (much like the SurfaceViewOverlay example in the API demos). I'm running into an issue trying to implement that method with an extended GLSurfaceView class. I've set up an example where I'm trying to do a combination of <a href="http://www.droidnova.com/android-3d-game-tutorial-part-i,312.html" rel="nofollow noreferrer">this demo</a> with the API Oerlay demo. If I try to cast to a Martin's VortexView object like this (replace lines 44-46 in the API demo)</p> <pre><code>VortexView glSurfaceView= (VortexView) findViewById(R.id.glsurfaceview); </code></pre> <p>I get a ClassCastException error (which is understandable, as I assume casting is fairly specific) so I guess I'm looking for a method to transfer the view from a GLSurfaceView instance to a new subclass or a way to set the rendering surface to an XML defined view for a subclass after it has been created.</p> <p>EDIT: I've made some progress trying to get this to work- in the API example the view XML uses (from ApiDemos/res/layout/surface_view_overlay.xml)</p> <pre><code> &lt;android.opengl.GLSurfaceView android:id="@+id/glsurfaceview" android:layout_width="match_parent" android:layout_height="match_parent" /&gt; </code></pre> <p>If I change that element to a<br> com.domain.project.VortexView it will do the casting correctly with the above code but generates Null Pointer Exceptions when it hits the surfaceCreated and surfaceChanged routines (I think it's the called methods in the GLThread class based on the line number) inside the GLSurfaceView class. So maybe I should change the question- How can I implement an extension for GLSurfaceView without generating NullPointerExceptions on surfaceCreated and surfaceChanged, or how can I debug them without having the source for GLSurfaceView.java?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload