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:


      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,


                                                                        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


                  // 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

                  // 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.




          public void onOpened(EMDKManager emdkManager) {

              try {


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

              } catch (ScannerException e) {


              } catch (Exception e) {





          public void onClosed() {




          public void onData(ScanDataCollection scanDataCollection) {

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



          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:


      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.