How to properly use GLES20.glVertexAttribPointer() on android with VBOs?
<p>I am trying to get a simple 2D square to appear on the screen, but I am running into a problem with the last argument in the method GLES20.glVertexAttribPointer().</p>

<p>Here's my code(the draw() method):</p>

<pre><code>public void draw(float[] matrix){
        int shaderHandle = shader.getShaderHandle();
        int mMVPMatrixHandle;

        GLES20.glUseProgram(shaderHandle);
        mPositionHandle = GLES20.glGetAttribLocation(shaderHandle, "vPosition");

        mMVPMatrixHandle = GLES20.glGetUniformLocation(shaderHandle, "uMVPMatrix");
        MyGLRenderer.checkGlError("glGetUniformLocation");

        GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, matrix, 0);
        MyGLRenderer.checkGlError("glUniformMatrix4fv");

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER,vbo);
        GLES20.glEnableVertexAttribArray(mPositionHandle);
        GLES20.glVertexAttribPointer(mPositionHandle,COORDS_PER_VERTEX,GLES20.GL_FLOAT,false,0,0);

        GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER,ibo);
        GLES20.glDrawElements(GLES20.GL_TRIANGLES,DRAW_ORDER.length,GLES20.GL_UNSIGNED_SHORT,null);

        GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER,0);
        GLES20.glBindBuffer(GLES20.GL_ELEMENT_ARRAY_BUFFER,0);
    }
</code></pre>

<p>The problem is in this line:</p>

<pre><code>GLES20.glVertexAttribPointer(mPositionHandle,COORDS_PER_VERTEX,GLES20.GL_FLOAT,false,0,0);
</code></pre>

<p>I'm using Android Studio, and it is telling me that I can't pass <code>0</code> as the last argument in this method, it requires a Buffer object.</p>

<p>In order to use my VBO, I'm told I must have a zero as the last argument. How do I do this?</p>

<p>The logcat entry I receive is as follows:</p>

<pre><code>06-23 22:27:23.098 2709-2709/? I/art: Not late-enabling -Xcheck:jni (already on)
06-23 22:27:23.222 2709-2709/com.example.android.opengl W/System: ClassLoader referenced unknown path: /data/app/com.example.android.opengl-2/lib/x86
06-23 22:27:23.362 2709-2709/com.example.android.opengl W/System: ClassLoader referenced unknown path: /data/app/com.example.android.opengl-2/lib/x86
06-23 22:27:23.432 2709-2730/com.example.android.opengl D/OpenGLRenderer: Use EGL_SWAP_BEHAVIOR_PRESERVED: true

                                                                          [ 06-23 22:27:23.439  2709: 2709 D/         ]
                                                                          HostConnection::get() New Host Connection established 0xab9e4670, tid 2709


                                                                          [ 06-23 22:27:23.472  2709: 2730 D/         ]
                                                                          HostConnection::get() New Host Connection established 0xaf4471b0, tid 2730
06-23 22:27:23.474 2709-2730/com.example.android.opengl I/OpenGLRenderer: Initialized EGL, version 1.4

                                                                          [ 06-23 22:27:23.506  2709: 2729 D/         ]
                                                                          HostConnection::get() New Host Connection established 0xab9e4ac0, tid 2729
06-23 22:27:23.557 2709-2729/com.example.android.opengl I/System.out: DEBUG
06-23 22:27:23.562 2709-2729/com.example.android.opengl E/Surface: getSlotFromBufferLocked: unknown buffer: 0xb4093c00
06-23 22:27:23.565 2709-2729/com.example.android.opengl E/AndroidRuntime: FATAL EXCEPTION: GLThread 129
                                                                          Process: com.example.android.opengl, PID: 2709
                                                                          java.lang.NullPointerException: Attempt to invoke virtual method 'int java.nio.Buffer.remaining()' on a null object reference
                                                                              at android.opengl.GLES20.glVertexAttribPointer(GLES20.java:1913)
                                                                              at com.example.android.opengl.Sprite.draw(Sprite.java:105)
                                                                              at com.example.android.opengl.MyGLRenderer.onDrawFrame(MyGLRenderer.java:76)
                                                                              at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1535)
                                                                              at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
06-23 22:27:23.607 2709-2730/com.example.android.opengl E/Surface: getSlotFromBufferLocked: unknown buffer: 0xa3b11230
</code></pre>