我正在改变脸部检测按钮的颜色。但问题是一旦检测到面部问题。应用程序崩溃,
public void onFaceDetection(Camera.Face[] faces, Camera c) {
if (faces.length > 0) {
Log.d("FaceDetection", "face detected X and Y are as: " + faces.length +
" Face 1 Location X: " + faces[0].rect.centerX() +
"Y: " + faces[0].rect.centerY());
Button capture2 = (Button) findViewById(R.id.button_capture);
capture2.setBackgroundColor(Color.RED);
} else {
Log.d("FaceDetection", "face detected X and Y are as: " + 0);
}
}
};
logcat的
11-25 00:45:01.309 2529-2529/videocaptureexample E/AndroidRuntime: at android.hardware.Camera$EventHandler.handleMessage(Camera.java:1015)
11-25 00:45:01.309 2529-2529/videocaptureexample E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
11-25 00:45:01.309 2529-2529/videocaptureexample E/AndroidRuntime: at android.os.Looper.loop(Looper.java:146)
11-25 00:45:01.309 2529-2529/videocaptureexample E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5635)
11-25 00:45:01.309 2529-2529/videocaptureexample E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
11-25 00:45:01.309 2529-2529/videocaptureexample E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
11-25 00:45:01.309 2529-2529/videocaptureexample E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
11-25 00:45:01.309 2529-2529/videocaptureexample E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
11-25 00:45:01.309 2529-2529/videocaptureexample E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
11-25 00:45:03.164 2529-2529/videocaptureexample I/Process: Sending signal. PID: 2529 SIG: 9