我已经看到了另一个类似的线程,并尝试了他们的建议,但同样的问题发生所以我不想劫持他们的线程所以我发布了一个不同的线程.Sorry。
无论如何,我正在尝试使用Eclipse和Android 4.2.2 api创建一个相机应用程序。每当我在设备上调试或运行应用程序时,我都会得到java.lang.IllegalStateException
。我知道如果有人可以在这里查看这是我的logcat跟踪:
06-02 15:35:32.069: W/dalvikvm(12329): threadid=1: thread exiting with uncaught exception (group=0x40d46930)
06-02 15:35:32.069: E/AndroidRuntime(12329): FATAL EXCEPTION: main
06-02 15:35:32.069: E/AndroidRuntime(12329): java.lang.IllegalStateException: Could not execute method of the activity
06-02 15:35:32.069: E/AndroidRuntime(12329): at android.view.View$1.onClick(View.java:3599)
06-02 15:35:32.069: E/AndroidRuntime(12329): at android.view.View.performClick(View.java:4204)
06-02 15:35:32.069: E/AndroidRuntime(12329): at android.view.View$PerformClick.run(View.java:17355)
06-02 15:35:32.069: E/AndroidRuntime(12329): at android.os.Handler.handleCallback(Handler.java:725)
06-02 15:35:32.069: E/AndroidRuntime(12329): at android.os.Handler.dispatchMessage(Handler.java:92)
06-02 15:35:32.069: E/AndroidRuntime(12329): at android.os.Looper.loop(Looper.java:137)
06-02 15:35:32.069: E/AndroidRuntime(12329): at android.app.ActivityThread.main(ActivityThread.java:5041)
06-02 15:35:32.069: E/AndroidRuntime(12329): at java.lang.reflect.Method.invokeNative(Native Method)
06-02 15:35:32.069: E/AndroidRuntime(12329): at java.lang.reflect.Method.invoke(Method.java:511)
06-02 15:35:32.069: E/AndroidRuntime(12329): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
06-02 15:35:32.069: E/AndroidRuntime(12329): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
06-02 15:35:32.069: E/AndroidRuntime(12329): at dalvik.system.NativeStart.main(Native Method)
06-02 15:35:32.069: E/AndroidRuntime(12329): Caused by: java.lang.reflect.InvocationTargetException
06-02 15:35:32.069: E/AndroidRuntime(12329): at java.lang.reflect.Method.invokeNative(Native Method)
06-02 15:35:32.069: E/AndroidRuntime(12329): at java.lang.reflect.Method.invoke(Method.java:511)
06-02 15:35:32.069: E/AndroidRuntime(12329): at android.view.View$1.onClick(View.java:3594)
06-02 15:35:32.069: E/AndroidRuntime(12329): ... 11 more
06-02 15:35:32.069: E/AndroidRuntime(12329): Caused by: java.lang.RuntimeException: takePicture failed
06-02 15:35:32.069: E/AndroidRuntime(12329): at android.hardware.Camera.native_takePicture(Native Method)
06-02 15:35:32.069: E/AndroidRuntime(12329): at android.hardware.Camera.takePicture(Camera.java:1095)
06-02 15:35:32.069: E/AndroidRuntime(12329): at android.hardware.Camera.takePicture(Camera.java:1040)
06-02 15:35:32.069: E/AndroidRuntime(12329): at com.example.de.vogella.camera.api.MakePhotoActivity.onClick(MakePhotoActivity.java:46)
06-02 15:35:32.069: E/AndroidRuntime(12329): ... 14 more
我在onClick()
方法中尝试了以下代码,当我尝试使用该应用时仍然遇到相同的错误:
if(camera == null)
{
// Warn user that camera is not available via "Toast" or similar.
} else {
camera.takePicture(null, null,new PhotoHandler(getApplicationContext()))
}
我也尝试了以下内容。我在类的顶部声明了mPhotoHandler
,我保留了其他变量,在onClick()
方法中我只放了这个代码:
mPhotoHandler = new PhotoHandler(getApplicationContext());
camera.takePicture(null, null,mPhotoHandler);
以下是我的onPause()
方法的代码:
protected void onPause() {
if (camera != null) {
camera.release();
camera = null;
}
super.onPause();
}
上述代码有问题吗?请告诉我。