Hey guys, I'm I guess what you would call an aspiring Android developer.  
I'm running through the tutorials trying to get a basic handle on things 
before I go out into the wild and try to brute force my way through my 
first app.  In other words, if I seem like I am confused, chances are I am. 
:)

Anyway, I'm running through the OpenGL tutorial, and I cannot for the life 
of me get the application to launch correctly.  The program compiles and 
installs fine, but when I go to run it I get an error saying that the 
application "unexpectedly closed."  I've been pulling my hair out trying to 
track down the issue, but the LogCat is a bit cryptic (to me) and seems to 
be referencing methods I didn't explicitly call, which makes it more 
difficult for me to know where to start.

I'm not sure what you guys need to see in order to help, but I attached the 
java files, the manifest, and the LogCat output.

Logcat Output:

12-27 14:27:05.768: W/ActivityThread(3493): Application 
com.wiley.openglplayground is waiting for the debugger on port 8100...12-27 
14:27:05.778: I/System.out(3493): Sending WAIT chunk12-27 14:27:05.878: 
I/dalvikvm(3493): Debugger is active12-27 14:27:05.978: I/System.out(3493): 
Debugger has connected12-27 14:27:05.978: I/System.out(3493): waiting for 
debugger to settle...12-27 14:27:06.179: I/System.out(3493): waiting for 
debugger to settle...12-27 14:27:06.379: I/System.out(3493): waiting for 
debugger to settle...12-27 14:27:06.579: I/System.out(3493): waiting for 
debugger to settle...12-27 14:27:06.779: I/System.out(3493): waiting for 
debugger to settle...12-27 14:27:06.979: I/System.out(3493): waiting for 
debugger to settle...12-27 14:27:07.180: I/System.out(3493): waiting for 
debugger to settle...12-27 14:27:07.380: I/System.out(3493): waiting for 
debugger to settle...12-27 14:27:07.580: I/System.out(3493): debugger has 
settled (1420)12-27 14:27:07.890: D/libEGL(3493): loaded 
/system/lib/egl/libGLES_android.so12-27 14:27:07.890: D/libEGL(3493): loaded 
/system/lib/egl/libEGL_adreno200.so12-27 14:27:07.900: D/libEGL(3493): loaded 
/system/lib/egl/libGLESv1_CM_adreno200.so12-27 14:27:07.900: D/libEGL(3493): 
loaded /system/lib/egl/libGLESv2_adreno200.so12-27 14:27:07.950: 
D/OpenGLRenderer(3493): Enabling debug mode 012-27 14:27:08.711: 
D/dalvikvm(3493): threadid=1: still suspended after undo (sc=1 dc=1)12-27 
14:28:21.132: D/AndroidRuntime(3493): Shutting down VM12-27 14:28:21.132: 
W/dalvikvm(3493): threadid=1: thread exiting with uncaught exception 
(group=0x40a601f8)12-27 14:28:21.252: E/AndroidRuntime(3493): FATAL EXCEPTION: 
main12-27 14:28:21.252: E/AndroidRuntime(3493): 
java.lang.NullPointerException12-27 14:28:21.252: E/AndroidRuntime(3493):     
at android.opengl.GLSurfaceView.surfaceCreated(GLSurfaceView.java:512)12-27 
14:28:21.252: E/AndroidRuntime(3493):     at 
android.view.SurfaceView.updateWindow(SurfaceView.java:533)12-27 14:28:21.252: 
E/AndroidRuntime(3493):     at 
android.view.SurfaceView.access$000(SurfaceView.java:81)12-27 14:28:21.252: 
E/AndroidRuntime(3493):     at 
android.view.SurfaceView$3.onPreDraw(SurfaceView.java:169)12-27 14:28:21.252: 
E/AndroidRuntime(3493):     at 
android.view.ViewTreeObserver.dispatchOnPreDraw(ViewTreeObserver.java:590)12-27 
14:28:21.252: E/AndroidRuntime(3493):     at 
android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1617)12-27 
14:28:21.252: E/AndroidRuntime(3493):     at 
android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)12-27 
14:28:21.252: E/AndroidRuntime(3493):     at 
android.os.Handler.dispatchMessage(Handler.java:99)12-27 14:28:21.252: 
E/AndroidRuntime(3493):     at android.os.Looper.loop(Looper.java:137)12-27 
14:28:21.252: E/AndroidRuntime(3493):     at 
android.app.ActivityThread.main(ActivityThread.java:4575)12-27 14:28:21.252: 
E/AndroidRuntime(3493):     at java.lang.reflect.Method.invokeNative(Native 
Method)12-27 14:28:21.252: E/AndroidRuntime(3493):     at 
java.lang.reflect.Method.invoke(Method.java:511)12-27 14:28:21.252: 
E/AndroidRuntime(3493):     at 
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)12-27
 14:28:21.252: E/AndroidRuntime(3493):     at 
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)12-27 14:28:21.252: 
E/AndroidRuntime(3493):     at dalvik.system.NativeStart.main(Native 
Method)12-27 14:28:21.442: I/Process(3493): Sending signal. PID: 3493 SIG: 9
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
package com.example.lessonone;

import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;

public class LessonOneActivity extends Activity {
	
	private GLSurfaceView mGLSurfaceView;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		System.out.println("onCreate called.");		
		super.onCreate(savedInstanceState);
		System.out.println("Super class constructor called.");
		
		mGLSurfaceView.setEGLContextClientVersion(2);
		mGLSurfaceView.setRenderer(new LessonOneRenderer());
		
		setContentView(mGLSurfaceView);
		System.out.println("OpenGL ES view created and set.");
	}
	
	@Override
	protected void onResume(){
		super.onResume();
		mGLSurfaceView.onResume();
		System.out.println("Resumed.");
	}
	
	@Override
	protected void onPause(){
		super.onPause();
		mGLSurfaceView.onPause();
		System.out.println("Paused");
	}
}
package com.example.lessonone;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.Matrix;

public class LessonOneRenderer implements GLSurfaceView.Renderer {
	private final FloatBuffer mTriangle1Vertices;
	private final FloatBuffer mTriangle2Vertices;
	private final FloatBuffer mTriangle3Vertices;
	
	private final int mBytesPerFloat = 4;
	
	private float[] mViewMatrix = new float[16];
	
	public LessonOneRenderer() {
		final float[] triangle1VerticesData = {
				// X, Y, Z,
	            // R, G, B, A
	            -0.5f, -0.25f, 0.0f,
	            1.0f, 0.0f, 0.0f, 1.0f,
	 
	            0.5f, -0.25f, 0.0f,
	            0.0f, 0.0f, 1.0f, 1.0f,
	 
	            0.0f, 0.559016994f, 0.0f,
	            0.0f, 1.0f, 0.0f, 1.0f };
		
		final float[] triangle2VerticesData = {
				// X, Y, Z,
	            // R, G, B, A
	            -0.5f, 0.25f, 0.0f,
	            1.0f, 0.0f, 0.0f, 1.0f,
	 
	            0.5f, 0.25f, 0.0f,
	            0.0f, 0.0f, 1.0f, 1.0f,
	 
	            0.0f, 0.559016994f, 0.0f,
	            0.0f, 1.0f, 0.0f, 1.0f };
		
		final float[] triangle3VerticesData = {
				// X, Y, Z,
	            // R, G, B, A
	            -0.5f, 0.25f, 0.0f,
	            1.0f, 0.0f, 0.0f, 1.0f,
	 
	            -0.5f, -0.25f, 0.0f,
	            0.0f, 0.0f, 1.0f, 1.0f,
	 
	            0.0f, 0.559016994f, 0.0f,
	            0.0f, 1.0f, 0.0f, 1.0f };
		
		// Initialize the buffers.
		mTriangle1Vertices = ByteBuffer.allocateDirect(triangle1VerticesData.length * mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer();
		mTriangle2Vertices = ByteBuffer.allocateDirect(triangle2VerticesData.length * mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer();
		mTriangle3Vertices = ByteBuffer.allocateDirect(triangle3VerticesData.length * mBytesPerFloat).order(ByteOrder.nativeOrder()).asFloatBuffer();
		
		mTriangle1Vertices.put(triangle1VerticesData).position(0);
		mTriangle2Vertices.put(triangle2VerticesData).position(0);
		mTriangle3Vertices.put(triangle3VerticesData).position(0);
	}

	@Override
	public void onDrawFrame(GL10 gl) {
		
		
	}

	@Override
	public void onSurfaceChanged(GL10 gl, int width, int height) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onSurfaceCreated(GL10 gl, EGLConfig config) {
		// Set background color to grey.
		GLES20.glClearColor(0.5f, 0.5f, 0.5f, 0.5f);
		
		// Position the eye behind the origin
		final float eyeX = 0.0f;
		final float eyeY = 0.0f;
		final float eyeZ = 1.5f;
		
		// We are looking toward the distance
		final float lookX = 0.0f;
		final float lookY = 0.0f;
		final float lookZ = -5.0f;
		
		// Set out up vector.  THis is where our head would be pointing were we holding the camera.
		final float upX = 0.0f;
		final float upY = 1.0f;
		final float upZ = 0.0f;
		
		Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);
		
		final String vertexShader =
			    "uniform mat4 u_MVPMatrix;      \n"     // A constant representing the combined model/view/projection matrix.
			 
			  + "attribute vec4 a_Position;     \n"     // Per-vertex position information we will pass in.
			  + "attribute vec4 a_Color;        \n"     // Per-vertex color information we will pass in.
			 
			  + "varying vec4 v_Color;          \n"     // This will be passed into the fragment shader.
			 
			  + "void main()                    \n"     // The entry point for our vertex shader.
			  + "{                              \n"
			  + "   v_Color = a_Color;          \n"     // Pass the color through to the fragment shader.
			                                            // It will be interpolated across the triangle.
			  + "   gl_Position = u_MVPMatrix   \n"     // gl_Position is a special variable used to store the final position.
			  + "               * a_Position;   \n"     // Multiply the vertex by the matrix to get the final point in
			  + "}                              \n";    // normalized screen coordinates.
		
		final String fragmentShader =
			    "precision mediump float;       \n"     // Set the default precision to medium. We don't need as high of a
			                                            // precision in the fragment shader.
			  + "varying vec4 v_Color;          \n"     // This is the color from the vertex shader interpolated across the
			                                            // triangle per fragment.
			  + "void main()                    \n"     // The entry point for our fragment shader.
			  + "{                              \n"
			  + "   gl_FragColor = v_Color;     \n"     // Pass the color directly through the pipeline.
			  + "}                              \n";
		
		// Load in the vertex shader.
		int vertexShaderHandle = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
		
		String shaderLog = null;
		
		if(vertexShaderHandle != 0){
			// Pass in the shader source
			GLES20.glShaderSource(vertexShaderHandle, vertexShader);
			
			// Compile the shader.
			GLES20.glCompileShader(vertexShaderHandle);
			
			// Get the compilation status.
			final int[] compileStatus = new int[1];
			GLES20.glGetShaderiv(vertexShaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
			
			// If the compilation failed, delete the shader.
			if (compileStatus[0] == 0){
				// Copy shader info log to String 'shaderLog' for throwing an exception.
				shaderLog = GLES20.glGetShaderInfoLog(vertexShaderHandle);
				GLES20.glDeleteShader(vertexShaderHandle);
				vertexShaderHandle = 0;
			}
		}
		
		if(vertexShaderHandle == 0){
			if(shaderLog == null){
				throw new RuntimeException("Error creating vertex shader.");
			}
			else{
				throw new RuntimeException(shaderLog);
			}
		}
		
		// Load in the fragment shader.
		int fragmentShaderHandle = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
		
		if(fragmentShaderHandle != 0){
			// Pass in the shader source.
			GLES20.glShaderSource(fragmentShaderHandle, fragmentShader);
			
			// Compile the shader.
			GLES20.glCompileShader(fragmentShaderHandle);
			
			// Get compilation status.
			final int[] compileStatus = new int[1];
			GLES20.glGetShaderiv(fragmentShaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
			
			if(compileStatus[0] == 0){
				// Copy shader info log to String 'shaderLog' for throwing an exception.
				shaderLog = GLES20.glGetShaderInfoLog(fragmentShaderHandle);
				GLES20.glDeleteShader(fragmentShaderHandle);
				fragmentShaderHandle = 0;
			}
		}
		
		if(fragmentShaderHandle == 0){
			if(shaderLog == null){
				throw new RuntimeException("Error creating fragment shader.");
			}
			else{
				throw new RuntimeException(shaderLog);
			}
		}
		
		// Create a program object and store the handle to it.
		int programHandle = GLES20.glCreateProgram();
		
		if(programHandle != 0){
			// Attach vertex shader to program.
			GLES20.glAttachShader(programHandle, vertexShaderHandle);
			
			// Attach fragment shader to program.
			GLES20.glAttachShader(programHandle, fragmentShaderHandle);
			
			// TODO Finish Lesson One!!!
		}
	}
}

Attachment: AndroidManifest.xml
Description: XML document

Reply via email to