Android应用程序在简单的OpenGL代码上崩溃了

时间:2014-06-07 16:04:06

标签: android eclipse opengl-es

我写了一个简单的Android应用程序来为屏幕绘制颜色。但是每次编译它都会崩溃。

这是我的代码

public class MainActivity extends ActionBarActivity {

GLSurfaceView glSurfaceView;
MyRenderer renderer = new MyRenderer();;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    glSurfaceView = new GLSurfaceView(this);
    glSurfaceView.setRenderer(renderer);
    setContentView(glSurfaceView);
}

}

public class MyRenderer  implements GLSurfaceView.Renderer{
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    gl.glClearColor(0f, 1f, 0f, 1f);
}

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {

}

@Override
public void onDrawFrame(GL10 gl) {
    gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
}

}

Logcat屏幕

06-07 12:11:35.505: D/AndroidRuntime(2096): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
06-07 12:11:35.505: W/linker(2096): libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
06-07 12:11:35.515: D/AndroidRuntime(2096): CheckJNI is ON
06-07 12:11:35.525: D/dalvikvm(2096): Trying to load lib libjavacore.so 0x0
06-07 12:11:35.525: D/dalvikvm(2096): Added shared lib libjavacore.so 0x0
06-07 12:11:35.535: D/dalvikvm(2096): Trying to load lib libnativehelper.so 0x0
06-07 12:11:35.545: D/dalvikvm(2096): Added shared lib libnativehelper.so 0x0
06-07 12:11:35.545: D/dalvikvm(2096): No JNI_OnLoad found in libnativehelper.so 0x0, skipping init
06-07 12:11:35.575: I/jdwp(1935): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.575: I/jdwp(1405): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.585: D/dalvikvm(2096): Note: class Landroid/app/ActivityManagerNative; has 179 unimplemented (abstract) methods
06-07 12:11:35.585: I/jdwp(1375): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.625: I/jdwp(2096): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.635: I/jdwp(1632): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.655: I/jdwp(1602): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.665: I/jdwp(1847): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.685: I/jdwp(1535): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.705: I/jdwp(1674): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.715: E/memtrack(2096): Couldn't load memtrack module (No such file or directory)
06-07 12:11:35.715: I/jdwp(1270): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.725: E/android.os.Debug(2096): failed to load memtrack module: -2
06-07 12:11:35.735: I/jdwp(1322): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.745: I/jdwp(1391): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.775: D/AndroidRuntime(2096): Calling main entry com.android.commands.pm.Pm
06-07 12:11:35.795: I/jdwp(1800): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.805: D/AndroidRuntime(2096): Shutting down VM
06-07 12:11:35.825: D/jdwp(2096): Got wake-up signal, bailing out of select
06-07 12:11:35.825: I/jdwp(1692): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.825: D/dalvikvm(2096): Debugger has detached; object registry had 1 entries
06-07 12:11:35.835: I/jdwp(1935): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.835: I/jdwp(1485): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.855: I/jdwp(1405): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.875: I/jdwp(1375): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.885: I/jdwp(1632): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.895: I/jdwp(1602): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.905: I/jdwp(1847): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.925: I/jdwp(1535): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.935: I/jdwp(1674): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.955: I/jdwp(1270): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.965: I/jdwp(1322): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.975: I/jdwp(1391): Ignoring second debugger -- accepting and dropping
06-07 12:11:35.985: I/jdwp(1800): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.005: I/jdwp(1692): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.105: D/AndroidRuntime(2107): >>>>>> AndroidRuntime START com.android.internal.os.RuntimeInit <<<<<<
06-07 12:11:36.105: W/linker(2107): libdvm.so has text relocations. This is wasting memory and is a security risk. Please fix.
06-07 12:11:36.115: D/AndroidRuntime(2107): CheckJNI is ON
06-07 12:11:36.125: D/dalvikvm(2107): Trying to load lib libjavacore.so 0x0
06-07 12:11:36.125: D/dalvikvm(2107): Added shared lib libjavacore.so 0x0
06-07 12:11:36.125: D/dalvikvm(2107): Trying to load lib libnativehelper.so 0x0
06-07 12:11:36.125: D/dalvikvm(2107): Added shared lib libnativehelper.so 0x0
06-07 12:11:36.125: D/dalvikvm(2107): No JNI_OnLoad found in libnativehelper.so 0x0, skipping init
06-07 12:11:36.145: D/dalvikvm(2107): Note: class Landroid/app/ActivityManagerNative; has 179 unimplemented (abstract) methods
06-07 12:11:36.155: I/jdwp(1935): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.155: I/jdwp(1405): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.175: I/jdwp(1375): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.195: I/jdwp(2107): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.215: I/jdwp(1632): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.235: I/jdwp(1602): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.255: I/jdwp(1847): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.265: E/memtrack(2107): Couldn't load memtrack module (No such file or directory)
06-07 12:11:36.265: E/android.os.Debug(2107): failed to load memtrack module: -2
06-07 12:11:36.265: I/jdwp(1535): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.285: I/jdwp(1674): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.295: I/jdwp(1270): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.305: I/jdwp(1322): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.325: I/jdwp(1391): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.335: I/jdwp(1800): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.345: D/AndroidRuntime(2107): Calling main entry com.android.commands.am.Am
06-07 12:11:36.355: I/jdwp(1692): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.355: D/AndroidRuntime(2107): Shutting down VM
06-07 12:11:36.355: D/dalvikvm(2107): Debugger has detached; object registry had 1 entries
06-07 12:11:36.355: I/AndroidRuntime(2107): NOTE: attach of thread 'Binder_1' failed
06-07 12:11:36.355: I/ActivityManager(1270): START u0 {act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.example.opengles/.MainActivity} from pid 2107
06-07 12:11:36.375: I/jdwp(1485): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.375: I/jdwp(1935): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.575: I/jdwp(1405): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.595: I/jdwp(1375): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.605: I/jdwp(1632): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.615: I/jdwp(1602): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.635: I/jdwp(1847): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.645: I/jdwp(1535): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.665: I/jdwp(1674): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.675: I/jdwp(1270): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.695: I/jdwp(1322): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.715: I/jdwp(1391): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.755: I/jdwp(1800): Ignoring second debugger -- accepting and dropping
06-07 12:11:36.775: I/jdwp(1692): Ignoring second debugger -- accepting and dropping

我尝试了一些解决方案,但它不起作用 我的程序有问题吗?

1 个答案:

答案 0 :(得分:0)

我尝试了你的代码,我发现它有效。我做了一些小改动。在下面找到我的代码 MainActivity.Java

package com.example.opengl;

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

public class MainActivity extends Activity {

    GLSurfaceView glSurfaceView;
    MyRenderer renderer = new MyRenderer();

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        glSurfaceView = new GLSurfaceView(this);
        glSurfaceView.setRenderer(renderer);
        setContentView(glSurfaceView);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

MyRenderer.java

package com.example.opengl;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.opengl.GLSurfaceView;

public class MyRenderer implements android.opengl.GLSurfaceView.Renderer{

    @Override
    public void onDrawFrame(GL10 gl) {
        // TODO Auto-generated method stub
        gl.glClearColor(0f, 1f, 0f, 1f);
    }

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

    }

    @Override
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        // TODO Auto-generated method stub
        gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
    }



}

的AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.opengl"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="16"
        android:targetSdkVersion="18" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.example.opengl.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>

如果您仍然遇到问题,请告诉我们