问题
I am going through the android tutorials on how to use graphics and animations. When I set my new content view the application crashes. I looked up the problem here and saw people with similar problems with this tutorial, but none of the solutions I have found have worked for me. I know people said the order of the lines when you set up your renderer is important but I have it in the same order they said to use. When I run in debug it seems to crash in the middle of the call to setContentView (which I can't see into, eclipse just says sorce not found at this part since I didn't write it).
Here is my main activity file: package com.example.graphicsretry;
import android.os.Bundle;
import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.content.Context;
public class MainActivity extends Activity {
private GLSurfaceView mGLView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mGLView = new MyGLSurfaceView(this);
/*mGLView = new GLSurfaceView(this);
mGLView.setEGLContextClientVersion(2);
MyGL20Renderer mg = new MyGL20Renderer();
mGLView.setRenderer(mg);*/
setContentView(mGLView);
}
}
class MyGLSurfaceView extends GLSurfaceView {
public MyGLSurfaceView(Context context){
super(context);
setEGLContextClientVersion(2);
MyGL20Renderer mg = new MyGL20Renderer();
setRenderer(mg);
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
}
}
This is my renderer class
package com.example.graphicsretry;
import android.opengl.GLSurfaceView;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLES20;
import javax.microedition.khronos.egl.EGLConfig;
public class MyGL20Renderer implements GLSurfaceView.Renderer {
public void onSurfaceCreated(GL10 unused, EGLConfig config) {
// Set the background frame color
GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
}
public void onDrawFrame(GL10 unused) {
// Redraw background color
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
}
public void onSurfaceChanged(GL10 unused, int width, int height) {
GLES20.glViewport(0, 0, width, height);
}
}
Here is my android manifest file. It has the uses-feature tag needed and two support texture tags (NOTE: I tried it without the support texture tags and it still crashed):
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.graphicsretry"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-feature android:glEsVersion="0x00020000" android:required="true" />
<supports-gl-texture android:name="GL_OES_compressed_ETC1_RGB8_texture" />
<supports-gl-texture android:name="GL_OES_compressed_paletted_texture" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.graphicsretry.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
I pasted my logcat file here in case it helps anyone: http://pastebin.com/EvB9NYJF
来源:https://stackoverflow.com/questions/17739215/setcontentview-crashes-android-emulator