所以我使用zxing扫描仪尝试获得一些结果,我试图处理如果人不扫描任何东西会发生什么。 目前,我试图这样:NullPointerException空白扫描结果
String scanResult = scanningResult.getContents();
if (scanResult.matches("")){
scanResult = "You didnt scan anything";
//I assume i need something similar to .setText?
}
else {
scanResult = scanningResult.getContents();
}
TextView results=(TextView)findViewById(R.id.noResult);
results.setText(scanResult);
但是,这是给我上的空白扫描一个NullPointerException。但如果正确扫描,则显示结果。任何线索为什么? (这是我第一次尝试更改基于文本关闭的结果,因此它可能是一些简单)
NPE指向'如果(scanResult.matches( “”)){' –