我正在开发一个应用程序,当我单击一次按钮后每 4 秒自动开始捕获图像..但我收到错误..这就是我正在做的
buttonClick.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
new Thread(new Runnable() {
public void run() {
while(true)
{
preview.camera.takePicture(shutterCallback, rawCallback,
jpegCallback);
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}).start();
}
});
上面的代码给出了错误..但是当我这样做时
buttonClick.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
preview.camera.takePicture(shutterCallback,jpegCallback);
}
});
它工作正常!
这是错误日志
`01-07 23:53:16.892: W/dalvikvm(1625): threadid=1: thread exiting with uncaught exception (group=0x4001d800)
01-07 23:53:16.912: E/AndroidRuntime(1625): FATAL EXCEPTION: main
01-07 23:53:16.912: E/AndroidRuntime(1625): java.lang.RuntimeException: Fail to connect to camera service
01-07 23:53:16.912: E/AndroidRuntime(1625): at android.hardware.Camera.native_setup(Native Method)
01-07 23:53:16.912: E/AndroidRuntime(1625): at android.hardware.Camera.<init>(Camera.java:110)
01-07 23:53:16.912: E/AndroidRuntime(1625): at android.hardware.Camera.open(Camera.java:90)
01-07 23:53:16.912: E/AndroidRuntime(1625): at com.android.mycamera.Preview.surfaceCreated(Preview.java:35)
01-07 23:53:16.912: E/AndroidRuntime(1625): at android.view.SurfaceView.updateWindow(SurfaceView.java:532)
01-07 23:53:16.912: E/AndroidRuntime(1625): at android.view.SurfaceView.dispatchDraw(SurfaceView.java:339)
01-07 23:53:16.912: E/AndroidRuntime(1625): at android.view.ViewGroup.drawChild(ViewGroup.java:1638)
`
任何帮助将不胜感激!