无法启动ZXing扫描仪

时间:2019-05-03 23:21:07

标签: android zxing

我正在开发一个使用ZXing条码扫描器解锁测验级别的android应用。 我的MainActivity提供了测验难度的选择。我想这样做,以便在我扫描QR码时,MainActivity会检查QR码是否有效,然后继续进行测验。我在课程public static String qrCodeResultValue中有一个字段 MainActivity.class:

if(difficulty.equals(Question.DIFFICULTY_HARD) || difficulty.equals(Question.DIFFICULTY_EXPERT)) {
//this doesn't open the ZXing scanner, but proceeds the next line
            startActivity(new Intent(getApplicationContext(), ScanCodeActivity.class));

//MainActivity.qrCodeResultValue here is null (the source of the error)          
if(MainActivity.qrCodeResultValue.equals(QuizUtils.CODE_HARD) || MainActivity.qrCodeResultValue.equals(QuizUtils.CODE_EXPERT)){
                Intent intent = new Intent(MainActivity.this, QuizActivity.class);
                intent.putExtra(EXTRA_DIFFICULTY, difficulty);
                startActivityForResult(intent, REQUEST_CODE_QUIZ);
            }else {
                Toast.makeText(this, "Invalid QR Code for this difficulty", Toast.LENGTH_LONG);
            }

        }else{
            Intent intent = new Intent(MainActivity.this, QuizActivity.class);
            intent.putExtra(EXTRA_DIFFICULTY, difficulty);
            startActivityForResult(intent, REQUEST_CODE_QUIZ);
        }

ScanCodeActivity.class应该启动QR码扫描仪,但是我的密码甚至没有输入。

ScanCodeActivity.class

public class ScanCodeActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {

    ZXingScannerView scannerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        scannerView = new ZXingScannerView(this);
        setContentView(scannerView);

    }

    @Override
    public void handleResult(Result result) {
        MainActivity.qrCodeResultValue = result.getText();
        onBackPressed();
    }
}

错误:

试图在空对象引用上调用虚拟方法'boolean java.lang.String.equals(java.lang.Object)'

0 个答案:

没有答案