2014-08-28 33 views
-1

我寫了一個簡單的代碼來測試GLSurfaceView。GLSurfaceView不起作用

package com.jeobin.test; 

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

public class MainActivity extends Activity { 
    GLSurfaceView view; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     view = new GLSurfaceView(this); 
     setContentView(view); 
    } 
} 

當我在代碼中添加setContentView(view)時,它會崩潰。這是我的清單。

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.jeobin.test" 
    android:versionCode="1" 
    android:versionName="1.0" > 
    <uses-feature android:glEsVersion="0x00020000" android:required="true" /> 
    <uses-sdk 
     android:minSdkVersion="8" 
     android:targetSdkVersion="19" /> 

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

eclipse出錯了嗎?

回答

0

你是什麼意思的「打破」?它可以運行嗎?爲了使用OpenGL ES,您必須編寫一個渲染器類,並使用setRenderer()將其設置爲GLSurfaceView。看看這個:http://www.learnopengles.com/android-lesson-one-getting-started/

+0

當我在我的note3中打開這個應用程序,它顯示「不幸的是,測試已經彎腰」。在這裏,我只是做一個測試代碼來測試GLSurface是否可以工作。在我的另一個代碼中,我寫了一個renderer.class。 – 2014-08-28 16:28:04

+0

我認爲問題在於您需要在調用setContentView之前將渲染器設置爲GLSurfaceView類。 – Tristram 2014-08-28 17:29:16