1

I am trying to run my project from android studio but I get in java.lang.RuntimeException error while executing doInBackground() and the app stopped I have sawed a lot of question about this but its didn't work.

Here is my code:

  import...

  public class LicensePlateProcessorAsync extends AsyncTask < LicensePlateProcessorParameter, String, Object > {
    private static final String TAG = "LPRWorker";
    private LicensePlateProcessorCallback listener;
    private Object HandlerThread;
    private Object LicensePlateProcessorParameter;
    private Object String;
    private java.lang.Object Object;
    public LicensePlateProcessorAsync(LicensePlateProcessorCallback listener) {
     this.listener = listener;
    }
    protected Object doInBackground(LicensePlateProcessorParameter...params) {
     LicensePlateProcessorParameter param = params[0];
     String path = param.getPath();
     float fResizeRatio = param.getResizeRatio();
     PreviewMode previewMode = param.getPreviewMode();
     int iMedianBlurKernelSize = param.getMedianBlurKernelSize();
     int iLineLength = param.getLineLength();
     publishProgress("Loading file");
     Mat mImage = null;
     try {
      ExifInterface exif = new ExifInterface(path);
      int rotationCode = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
      int rotationDegrees = 0;
      if (rotationCode == ExifInterface.ORIENTATION_ROTATE_90) {
       rotationDegrees = 90;
      } else if (rotationCode == ExifInterface.ORIENTATION_ROTATE_180) {
       rotationDegrees = 180;
      } else if (rotationCode == ExifInterface.ORIENTATION_ROTATE_270) {
       rotationDegrees = 270;
      }
      Matrix matrix = new Matrix();
      if (rotationDegrees != 0) {
       matrix.preRotate(rotationDegrees);
      }
      BitmapFactory.Options bmOptions = new BitmapFactory.Options();
      bmOptions.inJustDecodeBounds = false;
      Bitmap bitmapTmp = BitmapFactory.decodeFile(path, bmOptions);
      Bitmap bitmap;
      bitmap = Bitmap.createBitmap(
       bitmapTmp, 0, 0,
       bitmapTmp.getWidth(),
       bitmapTmp.getHeight(),
       matrix,
       true);

      mImage = new Mat();
      Utils.bitmapToMat(bitmap, mImage);
      bitmap.recycle();
     } catch (IOException e) {
      e.printStackTrace();
     } 

And the error is :

  java.lang.RuntimeException: An error occured
  while executing doInBackground()
  at android.os.AsyncTask$3.done(AsyncTask.java: 299)
  at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java: 352)
  at java.util.concurrent.FutureTask.setException(FutureTask.java: 219)
  at java.util.concurrent.FutureTask.run(FutureTask.java: 239)
  at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java: 230)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java: 1080)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java: 573)
  at java.lang.Thread.run(Thread.java: 856)
  Caused by: java.lang.NullPointerException
  at com.mhd_deeb.lprsvu.lpr_sit.LicensePlateProcessorAsync.doInBackground(LicensePlateProcessorAsync.java: 73)
  at com.mhd_deeb.lprsvu.lpr_sit.LicensePlateProcessorAsync.doInBackground(LicensePlateProcessorAsync.java: 29)
momo
  • 3,313
  • 2
  • 19
  • 37
mhd
  • 11
  • 2
  • It will help us a lot if you tell us which line 73 of the `LicensePlateProcessorAsync` class is. Please share the full code implementation if it is necessary. – Julio Lemus Oct 29 '19 at 18:25
  • line 73 is bitmapTmp.getWidth(), – mhd Oct 29 '19 at 18:51
  • Then, it means you are trying to get width from a null object, in this case `bitmapTmp `. Surely `BitmapFactory.decodeFile(path, bmOptions);` is returning null since `decodeFile` method uses the path to read a stream of bytes, make sure `path` is a valid path that points to the image file. That will solve it I think. – Julio Lemus Oct 29 '19 at 19:04
  • Probably your error could be fixed if the path is valid. I found here https://stackoverflow.com/questions/3388898/bitmapfactory-decodefile-returns-null-even-image-exists a situation like yours – Julio Lemus Oct 29 '19 at 19:36

0 Answers0