【问题标题】:Zbar Scanner Error java.lang.RuntimeException: cancelAutoFocus failedZbar 扫描仪错误 java.lang.RuntimeException:cancelAutoFocus 失败
【发布时间】:2020-05-31 13:25:57
【问题描述】:

我的应用程序包含条形码扫描仪,我使用了 Zbar 扫描仪并且它工作但以下错误不断出现,我搜索了很多我没有找到任何解决方案 错误:

java.lang.RuntimeException: cancelAutoFocus failed
java.lang.RuntimeException: cancelAutoFocus failed
    at android.hardware.Camera.native_cancelAutoFocus(Native Method)

我使用的代码:

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);

}

【问题讨论】:

  • 请尝试更新您的图书馆
  • @ShaluTD 怎么样!?我想我使用的是最新版本

标签: java android xml barcode zbar


【解决方案1】:

我在代码中发现了问题 我应该从 onResume 方法中删除 mScannerView.startCamera()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-01
    • 2014-02-06
    • 1970-01-01
    相关资源
    最近更新 更多