“java.lang.IllegalArgumentException:沒有配置匹配configSpec”開啟相機意圖
這是我簡單的相機意圖演示,其中我只有一個活動…..
package x.y; import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.widget.ImageView; public class PhotoShoot extends Activity { final static int CAMERA_RESULT = 0; ImageView imv; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); startActivityForResult(i, CAMERA_RESULT); } protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode == RESULT_OK) { Bundle extras = intent.getExtras(); Bitmap bmp = (Bitmap) extras.get("data"); imv = (ImageView) findViewById(R.id.ReturnedImageView); imv.setImageBitmap(bmp); } } }
和Layout main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ImageView android:id="@+id/ReturnedImageView" android:layout_width="wrap_content" android:layout_height="wrap_content"> </ImageView> </LinearLayout>
清單…
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="x.y" android:versionCode="1" android:versionName="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".PhotoShoot" 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>
在Android模擬器2.2中幾秒鐘後投擲“強制關閉”,從“相機意圖”開始啟動以下異常…
07-06 15:26:00.999: ERROR/AndroidRuntime(544): FATAL EXCEPTION: GLThread 11 07-06 15:26:00.999: ERROR/AndroidRuntime(544): java.lang.IllegalArgumentException: No configs match configSpec 07-06 15:26:00.999: ERROR/AndroidRuntime(544): at android.opengl.GLSurfaceView/">SurfaceView$BaseConfigChooser.chooseConfig(GLSurfaceView.java:760) 07-06 15:26:00.999: ERROR/AndroidRuntime(544): at android.opengl.GLSurfaceView$EglHelper.start(GLSurfaceView.java:916) 07-06 15:26:00.999: ERROR/AndroidRuntime(544): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1246) 07-06 15:26:00.999: ERROR/AndroidRuntime(544): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1116)
任何想法?
這實際上是一個更大的問題的一部分,我希望通過在這裡釋出,其他經歷過這個錯誤的人會讀這個條目.我同樣希望,如果我的任何結論不正確,有人會提出更明確的解釋和/或解決方案.
核心問題是OpenGL的支援.從2.2開始,Android支援OpenGL ES 2.0,從4.0.3開始,Android模擬器支援OpenGL ES 2.0.使用OpenGL ES 2.0的程式碼在4.0.3之前不能在模擬器上執行. [顯然,相機在Android 2.2從ES 1.0切換到2.0]
但這不是全部!我沒有遇到任何Android文件提到,為了支援Open GL ES 2.0模擬,您的盒子的顯示卡晶片組和驅動程式也必須支援OpenGL 2.0.因此,如果在AVD上啟用GPU模擬,並且仍然遇到此錯誤,請執行以下操作:
1)檢視顯示卡上的規格,並訪問晶片組製造商的網站,以確定晶片組是否相容OpenGL 2.0.如果不是,你是S.O.L.並且必須通過實際的Android裝置而不是模擬器來堅持除錯.
2)確定您是否擁有晶片組的最新圖形驅動程式.通過Microsoft獲得的驅動程式(如果您使用Windows)通常不支援OpenGL,因此您需要從製造商下載最新的驅動程式.
我希望這有幫助.
程式碼日誌版權宣告:
翻譯自:http://stackoverflow.com/questions/6594636/java-lang-illegalargumentexception-no-configs-match-configspec-while-openin