title: android runtime error using zxing barcode API , unable to find a class in the API
body: <p>I’m writing a vehicle barcode scanner activity using (zxing 2.2 API &amp; its core.jar) &amp; I’m starting to test the functionality before going further.</p>
  
  <p>I’m getting a "run time error" when trying to launch the activity.</p>
  
  <p><strong>Actual Error snippet :
  10-08 04:36:49.308: E/dalvikvm(780): Could not find class 'com.google.zxing.RGBLuminanceSource', referenced from method com.toyota.toyotaownerspoc.barcode.ScanVinFromBarcodeActivity.cameraBytesToBinaryBitmap
  -08 04:36:49.326: E/dalvikvm(780): Could not find class 'com.google.zxing.MultiFormatReader', referenced from method com.toyota.toyotaownerspoc.barcode.ScanVinFromBarcodeActivity.decodeBitmapToString</strong></p>
  
  <p>The activity (ScanVinFromBarcodeActivity) crashes after this point. </p>
  
  <p>The classes below are actually resolved via Eclipse in my “ScanVinFromBarcodeActivity)” activity , when I’m writing the code, and compile, but not found at run time</p>
  
  <p><strong>com.google.zxing.MultiFormatReader //not found at run time
  com.google.zxing.RGBLuminanceSource //not found at run time</strong></p>
  
  <p><strong>1)    “Service” activity that contains the button that launches my scanner activity:</strong></p>
  
  <pre><code>package com.toyota.toyotaownerspoc.service;
  
  import com.toyota.toyotaownerspoc.R;
  import com.toyota.toyotaownerspoc.barcode.ScanVinFromBarcodeActivity;
  import com.toyota.toyotaownerspoc.nearby.Nearby;
  
  import android.app.Activity;
  import android.content.Intent;
  
  import android.os.Bundle;
  import android.view.View;
  
  public class Service extends Activity {
  
      private View scanVinButton = null;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_service);
  
          scanVinButton = findViewById(R.id.scanVinButton);
  
          scanVinButton.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
  
                  Intent i = new Intent(v.getContext(),
                          ScanVinFromBarcodeActivity.class);
                  startActivity(i);
  
              }
          });
      }
  
  }
  </code></pre>
  
  <p><strong>2)    The layout of the Service activity:</strong></p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".Service" &gt;
  
      &lt;Button
          android:id="@+id/scanVinButton"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_centerHorizontal="true"
          android:layout_marginBottom="16dp"
          android:text="Scan VIN" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>Now to the actual activity that is having the runtime error &amp; crash </p>
  
  <p><strong>3)    Actual “ScanVinFromBarcodeActivity” activity that contains the barcode scanner &amp; (uses zxing 2.2 liberary &amp; core.jar):</strong></p>
  
  <pre><code>package com.toyota.toyotaownerspoc.barcode;
  import com.google.zxing.BinaryBitmap;
  import com.google.zxing.ChecksumException;
  import com.google.zxing.FormatException;
  import com.google.zxing.MultiFormatReader; //found via import at compile time, however was found at run time 
  import com.google.zxing.NotFoundException;
  import com.google.zxing.RGBLuminanceSource;//found via import at compile time, however was found at run time 
  import com.google.zxing.Reader;
  import com.google.zxing.Result;
  import com.google.zxing.common.HybridBinarizer;
  import android.app.Activity;
  import android.content.pm.PackageManager;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.hardware.Camera;
  import android.hardware.Camera.CameraInfo;
  import android.hardware.Camera.PictureCallback;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.View;
  import android.widget.TextView;
  import android.widget.Toast;
  import com.toyota.toyotaownerspoc.R;
  
  public class ScanVinFromBarcodeActivity extends Activity {
      private Camera camera;
      private int cameraId = 0;
      private TextView VINtext = null;
      private View scanButton = null;
      // bitmap from camera
      private Bitmap bmpOfTheImageFromCamera = null;
  
      PictureCallback jpegCallback = new PictureCallback() {
          public void onPictureTaken(byte[] imgData, Camera camera) {
              // get the bitmap from camera imageData
              bmpOfTheImageFromCamera = BitmapFactory.decodeByteArray(imgData, 0,
                      imgData.length);
              BinaryBitmap bitmap = null;
              if (bmpOfTheImageFromCamera != null) {
                  // convert bitmap to binary bitmap
                  bitmap = cameraBytesToBinaryBitmap(bmpOfTheImageFromCamera);
  
                  if (bitmap != null) {
                      // decode the VIN
                      String VIN = decodeBitmapToString(bitmap);
                      Log.d("ClassScanViewBarcodeActivity , scanButton.setOnClickListener(): ",
                              VIN);
                      VINtext.setText(VIN);
                  } else {
                      Log.d("ClassScanViewBarcodeActivity , scanButton.setOnClickListener(): bitmap=",
                              String.valueOf(bitmap));
                  }
              } else {
                  Log.d("ClassScanViewBarcodeActivity , scanButton.setOnClickListener(): bmpOfTheImageFromCamera = ",
                          String.valueOf(bmpOfTheImageFromCamera));
              }
          }
  
      };// jpegCallback implementation
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_barcode_vin_scanner);
  
          // do we have any camera's on this device
          // check for back camera
          if (!getPackageManager()
                  .hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
              Toast.makeText(this, "No camera on this device", Toast.LENGTH_LONG)
                      .show();
          } else { // check for front camera
              cameraId = findFrontFacingCamera();
              if (cameraId &lt; 0) {
                  Toast.makeText(this, "No front facing camera found.",
                          Toast.LENGTH_LONG).show();
              } else {
                  camera = Camera.open(cameraId);
              }
          }// end else ,check for front camera
  
          // if camera is not null , than display incoming images on a preview screen on SurfaceView
          if (camera != null) {
              //implement later 
          }
  
          // create text area &amp; scan button
          VINtext = (TextView) findViewById(R.id.mytext);
          scanButton = findViewById(R.id.webbutton);
  
          scanButton.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                  camera.takePicture(null, null, jpegCallback);
  
              }
          });
  
      }// end onCreate
  
      private int findFrontFacingCamera() {
          int cameraId = -1;
          // Search for the front facing camera
          int numberOfCameras = Camera.getNumberOfCameras();
          for (int i = 0; i &lt; numberOfCameras; i++) {
              CameraInfo info = new CameraInfo();
              Camera.getCameraInfo(i, info);
              if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
                  Log.d("ClassScanViewBarcodeActivity , findFrontFacingCamera(): ",
                          "Camera found");
                  cameraId = i;
                  break;
              }
          }
          return cameraId;
      }// end findFrontFacingCamera()
  
      @Override
      protected void onPause() {
          if (camera != null) {
              camera.release();
              camera = null;
          }
          super.onPause();
      }// end onPause()
  
      public String decodeBitmapToString(BinaryBitmap bitmap) {
          Reader reader = null;
          Result result = null;
          String textResult = null;
          try {
  
              reader = new MultiFormatReader();
              if (bitmap != null) {
                  result = reader.decode(bitmap);
                  if (result != null) {
                      textResult = result.getText();
                  } else {
                      Log.d("ClassScanViewBarcodeActivity , String decodeBitmapToString (BinaryBitmap bitmap): result = ",
                              String.valueOf(result));
                  }
              } else {
                  Log.d("ClassScanViewBarcodeActivity , String decodeBitmapToString (BinaryBitmap bitmap): bitmap = ",
                          String.valueOf(bitmap));
              }
              /*
               * byte[] rawBytes = result.getRawBytes(); BarcodeFormat format =
               * result.getBarcodeFormat(); ResultPoint[] points =
               * result.getResultPoints();
               */
  
          } catch (NotFoundException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (ChecksumException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          } catch (FormatException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
  
          }
  
          return textResult;
      }// end decodeBitmapToString (BinaryBitmap bitmap)
  
      public BinaryBitmap cameraBytesToBinaryBitmap(Bitmap bitmap) {
          BinaryBitmap binaryBitmap = null;
          if (bitmap != null) {
  
              int[] pixels = new int[bitmap.getHeight() * bitmap.getWidth()];
              bitmap.getPixels(pixels, 0, 0, bitmap.getWidth() - 1,
                      bitmap.getHeight() - 1, bitmap.getWidth(),
                      bitmap.getHeight());
  
              RGBLuminanceSource source = new RGBLuminanceSource(
                      bitmap.getWidth(), bitmap.getHeight(), pixels);
  
              HybridBinarizer bh = new HybridBinarizer(source);
              binaryBitmap = new BinaryBitmap(bh);
          } else {
              Log.d("ClassScanViewBarcodeActivity , cameraBytesToBinaryBitmap (Bitmap bitmap): bitmap = ",
                      String.valueOf(bitmap));
          }
  
          return binaryBitmap;
      }
  
  }// end activity
  </code></pre>
  
  <p><strong>4)    Layout of ScanVinFromBarcodeActivity activity :</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="vertical"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:padding="20dip"
      &gt;
  
  &lt;TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:textColor="@color/mbackground1"
  android:gravity="center_horizontal"
  android:text="@string/decode_label"
  android:padding="20dip" /&gt;
  
  &lt;TextView
  android:id="@+id/mytext"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:gravity="center_horizontal"
  android:background="@color/mbackground2" 
  android:textColor="@color/mytextcolor" 
  android:padding="20dip"/&gt;
  
  
  &lt;TextView
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/continue_label"
  android:gravity="center_horizontal"
  android:textColor="@color/mytextcolor"
  android:padding="20dip"/&gt;
  
  &lt;Button 
  android:id="@+id/webbutton"
  android:layout_width="fill_parent"
  android:layout_height="wrap_content"
  android:text="@string/web_button"
  android:textColor="@color/mytextcolor"/&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Eclipse is able to resolve the classes, I have used 2 other “core.jar” files, and also compiled my own version, but still these classes cannot be found at runtime.</p>
  
  <p>I even used the "jar xf" command and exploded the core-2.2.jar and found the two classes were they should be, please see below:</p>
  
  <p><img src="https://i.stack.imgur.com/iGa5M.png" alt="extracted core.jar"></p>
  
  <p>Any help would be appreciated. </p>
  
  <p>Thanks </p>