Monday, June 10, 2013

[android help] Android: attempting to start OpenGL activity, app crashes


Android: attempting to start OpenGL activity, app crashes



I'm a newbie to Android development. Please bear with me if this question is trivial.


I have a main activity which contains a button:



android:id="@+id/single_player"
style="@style/ButtonTheme"
android:text="Single Player"
android:visibility="visible"
android:onClick="OpenGameActivity" />


and a method inside the main activity for the button to route to:



public void OpenGameActivity()
{
Intent intent = new Intent(MainActivity.this, GameActivity.class);
startActivity(intent);
}


Now, the GameActivity.class is an activity for creating a GLSurfaceView:



import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.view.MenuItem;

public class GameActivity extends Activity {
private GLSurfaceView GridView;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Create a GLSurfaceView instance and set it
// as the ContentView for this Activity.
GridView = new GameView(this);
setContentView(GridView);
}


GameView is a simple implementation of GLSurfaceView which creates GameRender, a simple implementation of GLSurfaceView.Renderer. I set up the Activity, SurfaceView, and Renderer all based on the guide at http://developer.android.com/training/graphics/opengl/environment.html The renderer looks like this:



import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import javax.microedition.khronos.opengles.GL10;

public class GameRender implements GLSurfaceView.Renderer {


@Override
public void onDrawFrame(GL10 unused) {
// Redraw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
}

@Override
public void onSurfaceCreated(GL10 gl10, javax.microedition.khronos.egl.EGLConfig eglConfig) {
GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
}

@Override
public void onSurfaceChanged(GL10 gl10, int width, int height) {
GLES20.glViewport(0, 0, width, height);
}
}


the problem is, every time I click the button from my Android phone which should start the new activity, the app crashes. What am I doing wrong?


I did my research before posting this, so for clarification I DID add the new activity to the manifest:



android:name=".MainActivity"
android:label="@string/app_name" >







android:name=".GameActivity"
android:parentActivityName=".MainActivity" >
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />



.

stackoverflow.comm

No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...