0

I'm trying to implement google's barcode scanner within my application.

The following code calls the barcode activity:

public void onClick(View v) {
    if (v.getId() == R.id.read_barcode) {
        Intent intent = new Intent(this, BarcodeCaptureActivity.class);
        intent.putExtra(BarcodeCaptureActivity.AutoFocus, autoFocus.isChecked());
        intent.putExtra(BarcodeCaptureActivity.UseFlash, useFlash.isChecked());

        startActivityForResult(intent, RC_BARCODE_CAPTURE);
    }
}

It then jumps to this part of the Activity.java code:

enter image description here

It throws the flag Source code does not match byte code and returns to the calling function where it then crashes with an InflationException that points to an XML file.

On further inspection, many of the imports are red:

enter image description here

As a result, there are many error flags on Activity.java. The code still compiles and runs up until the OnClick method is hit. I have tried following this and this on SO to no success. TIA

charwayne
  • 103
  • 1
  • 3
  • 18

1 Answers1

0

You should use an Android emulator (or real device) with the same api level as the compileSdkVersion in your Gradle file.

Uriel Frankel
  • 14,304
  • 8
  • 47
  • 69
  • I started at my physical device's API level but changed it at the suggestion of other people's working solutions. So far, this has not had any net effect on the ability to run my code. – charwayne Jan 10 '18 at 13:08
  • I assume if you use real device you might have different code since every company would compile the code by themself. Can you try this with emulator? – Uriel Frankel Jan 10 '18 at 13:14
  • An emulator wouldn't work for me, I need a specific internet connection to run the app. This leaves me to using a work tablet as my physical device. – charwayne Jan 11 '18 at 15:48
  • If you need a specific port you can do 'adb forward ..' – Uriel Frankel Jan 11 '18 at 16:10