致命的异常GLTHREAD 123

时间:2013-12-30 10:43:24

标签: java android eclipse opengl-es

这是我在Android开发中学习opengl时的演示程序 它显示NullPointerException致命异常运行时除外等...帮我解决这个问题我发送2个java文件...这只是我在android应用程序项目中修改过的文件....

FirstOpenGLProjectActivity.java

 package com.example.firstopenglproject;

 import android.app.Activity;
 import android.app.ActivityManager;
 import android.content.Context;
 import android.content.pm.ConfigurationInfo;
 import android.opengl.GLSurfaceView;
 import android.os.Build;
 import android.os.Bundle;
 import android.widget.Toast;

 public class FirstOpenGLProjectActivity extends Activity {
/**
 * Hold a reference to our GLSurfaceView
 */
private GLSurfaceView glSurfaceView;
private boolean rendererSet = false;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    glSurfaceView = new GLSurfaceView(this);

    // Check if the system supports OpenGL ES 2.0.
    final ActivityManager activityManager =
        (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);

    final ConfigurationInfo configurationInfo =
        activityManager.getDeviceConfigurationInfo();
    /*

    final boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;
     */
    // Even though the latest emulator supports OpenGL ES 2.0,
    // it has a bug where it doesn't set the reqGlEsVersion so
    // the above check doesn't work. The below will detect if the
    // app is running on an emulator, and assume that it supports
    // OpenGL ES 2.0.
    final boolean supportsEs2 =
        configurationInfo.reqGlEsVersion >= 0x20000
            || (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1
             && (Build.FINGERPRINT.startsWith("generic")
              || Build.FINGERPRINT.startsWith("unknown")
              || Build.MODEL.contains("google_sdk")
              || Build.MODEL.contains("Emulator")
              || Build.MODEL.contains("Android SDK built for x86")));

    if (supportsEs2) {
        // Request an OpenGL ES 2.0 compatible context.
        glSurfaceView.setEGLContextClientVersion(2);

        // Assign our renderer.
        glSurfaceView.setRenderer(new FirstOpenGLProjectRenderer());
        rendererSet = true;
    } else {
        /*
         * This is where you could create an OpenGL ES 1.x compatible
         * renderer if you wanted to support both ES 1 and ES 2. Since we're
         * not doing anything, the app will crash if the device doesn't
         * support OpenGL ES 2.0. If we publish on the market, we should
         * also add the following to AndroidManifest.xml:
         * 
         * <uses-feature android:glEsVersion="0x00020000"
         * android:required="true" />
         * 
         * This hides our app from those devices which don't support OpenGL
         * ES 2.0.
         */
        Toast.makeText(this, "This device does not support OpenGL ES 2.0.",
            Toast.LENGTH_LONG).show();
        return;
    }

    setContentView(glSurfaceView);
}

@Override
protected void onPause() {
    super.onPause();

    if (rendererSet) {
        glSurfaceView.onPause();
    }
}

@Override
protected void onResume() {
    super.onResume();

    if (rendererSet) {
        glSurfaceView.onResume();
    }
}

}

其他文件是FirstOpenGLProjectRenderer.java

 package com.example.firstopenglproject;

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

 import android.opengl.GLSurfaceView.Renderer;

 public class FirstOpenGLProjectRenderer implements Renderer
 {

private static final String GL_COLOR_BUFFER_BIT = null;

@Override
public void onDrawFrame(GL10 glUnused) {
// Clear the rendering surface.
glClear(GL_COLOR_BUFFER_BIT);
}

private void glClear(String glColorBufferBit) {
    // TODO Auto-generated method stub

}

@Override
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
// Set the OpenGL viewport to fill the entire surface.
glViewport(0, 0, width, height);
}

private void glViewport(int i, int j, int width, int height) {
    // TODO Auto-generated method stub

}

@Override
public void onSurfaceCreated(GL10 glUnused, EGLConfig config) {
    glClearColor(1.0f, 0.0f, 0.0f, 0.0f);
    }

private void glClearColor(float f, float g, float h, float i) {
    // TODO Auto-generated method stub

}

 }

当我创建一个新的Android应用程序项目时,这是我面对的问题,每次都可以有人建议我解决这个“致命异常”,“NullPointerException”问题.... 我需要重新安装所有eclipse ... sdk ...?

1 个答案:

答案 0 :(得分:0)

为什么这条线存在? GL_COLOR_BUFFER_BIT是GL定义的宏,在GL中具有特定值,您不能使用NULL覆盖。删除它,然后再试一次。

private static final String GL_COLOR_BUFFER_BIT = null;