I made a project with navigation tabs. When i click barcode tab it doesnt work. Can u help me to solve this error.
This is my MainApplication.class, I used switch-case structure, when i click barcode tab it doesnt work.
case R.id.btnbarkod:
Intent indent = new Intent(MainActivity.this, BarkodActivity.class);
startActivity(indent);
return true;
Here is my BarcodeActivity,
public class BarkodActivity extends AppCompatActivity implements ZXingScannerView.ResultHandler {
ZXingScannerView ScannerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(ScannerView);
ScannerView = new ZXingScannerView(this);
}
@Override
public void handleResult(Result result) {
String barkod = result.getText();
Toast.makeText(this, barkod, Toast.LENGTH_SHORT).show();
}
@Override
protected void onPause() {
super.onPause();
ScannerView.stopCamera();
}
@Override
protected void onResume() {
super.onResume();
ScannerView.setResultHandler(this);
ScannerView.startCamera();
}
}
In onCreate
, you do setContentView(ScannerView);
, but ScannerView
is still empty at this point: it is initialized the line below. Therefore: initialize ScannerView
before calling setContentView
.