2 Replies Latest reply on Jul 20, 2016 3:38 AM by none none

    BarcodeManager null pointer exception on EMDK 4.2

    none none

      Good morning.

       

      I'm having some troubles trying to instantiate the BarcodeManager. Im following this example:
      http://techdocs.zebra.com/emdk-for-android/4-0/tutorial/tutBasicScanningAPI/

       

      The problem is that, when i try to instantiate the BarcodeManager in the *onOpen* method (barcodeManager = (BarcodeManager)emdkManager.getInstance(EMDKManager.FEATURE_TYPE.BARCODE);) a NullPointerException is thrown.

       

      I created the following class:

      public class ScannerZebra implements EMDKListener,

                                                                        StatusListener,

                                                                        DataListener {

       

          private String TAG = getClass().getName();

       

          private Context context;

          private EMDKManager emdkManager = null;

          private BarcodeManager barcodeManager = null;

          private Scanner scanner = null;

       

       

          public ScannerZebra(Context context) {

              this.context = context;

       

              EMDKResults results = EMDKManager.getEMDKManager(context, this);

              if (results.statusCode != EMDKResults.STATUS_CODE.SUCCESS) {

                  Log.i(TAG, "Error inicializando EMDK");

              }

          }

       

          // Method to initialize and enable Scanner and its listeners
          private void initializeScanner() throws ScannerException {

              if (scanner == null) {

                  // Get the Barcode Manager object
                  barcodeManager = (BarcodeManager) emdkManager.getInstance(EMDKManager.FEATURE_TYPE.BARCODE);

                  // Get default scanner defined on the device
                  scanner = barcodeManager.getDevice(BarcodeManager.DeviceIdentifier.DEFAULT);

                  // Add data and status listeners
                  scanner.addDataListener(this);

                  scanner.addStatusListener(this);

                  // Hard trigger. When this mode is set, the user has to manually
                  // press the trigger on the device after issuing the read call.
                  scanner.triggerType = Scanner.TriggerType.HARD;

                  // Enable the scanner
                  scanner.enable();

                  // Starts an asynchronous Scan. The method will not turn ON the
                  // scanner. It will, however, put the scanner in a state in which
                  // the scanner can be turned ON either by pressing a hardware
                  // trigger or can be turned ON automatically.
                  scanner.read();

              }

          }

       

          @Override
          public void onOpened(EMDKManager emdkManager) {

              try {

                  initializeScanner();

                  Log.i(TAG, "ZEBRA inicializado");

              } catch (ScannerException e) {

                  e.printStackTrace();

              } catch (Exception e) {

                  e.printStackTrace();

              }

          }

       

          @Override
          public void onClosed() {

       

          }

       

          @Override
          public void onData(ScanDataCollection scanDataCollection) {

              Log.i(TAG, "Datos leídos: " + scanDataCollection.getResult().toString());

          }

       

          @Override
          public void onStatus(StatusData statusData) {

       

          }

      }

       

      Im making the instance on a onCreate Activity method: scannerZebra = new ScannerZebra(getApplicationContext());

       

      Searching in this forums i found the following link:

      https://developer.zebra.com/thread/31555

      BarcodeManager null referenceIt seems the same problem, so i downloaded again the EMDK4.2 libs and reinstalled them (from here: https://portal.motorolasolutions.com/Support/US-EN/Resolution?solutionId=102252), but this is not solving the problem.

       

      What can be happening?

       

      Im using Android Studio 2.1.2 over Mac OSX 10.11.5 with a TC75.

       

      Thanks and regards.