my app contains barcode scanner, i used Zbar scanner and it worked but the following error keeps appearing and I searched alot I didn't find any solution the error :
java.lang.RuntimeException: cancelAutoFocus failed
java.lang.RuntimeException: cancelAutoFocus failed
at android.hardware.Camera.native_cancelAutoFocus(Native Method)
the code I used:
private void initScanner(){
mScannerView = new ZBarScannerView(this);
scannView.addView(mScannerView);
mScannerView.setResultHandler(this);
mScannerView.startCamera();
mScannerView.setAutoFocus(true);
mScannerView.setSoundEffectsEnabled(true);
mScannerView.setContentDescription("barcode scanner ");
//scanResult.setText("scan barcode automatically");
mScannerView.setClickable(true);
}
@Override
public void handleResult(me.dm7.barcodescanner.zbar.Result rawResult) {
nameOfInputItems.requestFocus();
ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100);
tg.startTone(ToneGenerator.TONE_PROP_BEEP);
// nameOfInputItems.requestFocus();
if (rawResult != null) {
if (rawResult.getContents() == null) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(this, "done!", Toast.LENGTH_LONG).show();
scanResult.setText(rawResult.getContents());
barCode=scanResult.getText().toString();
}
} mScannerView.resumeCameraPreview(this);
}
i found the problem in the code I should remove mScannerView.startCamera() from onResume method