title: "Unfortunately, app has stopped" java.lang.RuntimeException: Unable to start activity ComponentInfo CAMERA APP
body: <p>So, I've been following this tutorial on YouTube for our app and since I barely know anything about app development (self-studying) I manually typed it so I could know which lines had these codes and..I just don't know what's wrong with it when I followed everything in the video (or I probably missed something.) My app won't run. </p>
  
  <pre><code>`08-27 16:50:41.336 4192-4192/e.alasse.opencv E/MultiWindowProxy: getServiceInstance failed!
  08-27 16:50:41.818 4192-4192/e.alasse.opencv E/AndroidRuntime: FATAL EXCEPTION: main
  Process: e.alasse.opencv, PID: 4192
  java.lang.RuntimeException: Unable to start activity ComponentInfo{e.alasse.opencv/e.alasse.opencv.OpenCamera}: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class ImageView
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2572)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654)
      at android.app.ActivityThread.-wrap11(ActivityThread.java)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488)
      at android.os.Handler.dispatchMessage(Handler.java:111)
      at android.os.Looper.loop(Looper.java:207)
      at android.app.ActivityThread.main(ActivityThread.java:5728)
      at java.lang.reflect.Method.invoke(Native Method)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
   Caused by: android.view.InflateException: Binary XML file line #20: Binary XML file line #20: Error inflating class ImageView
      at android.view.LayoutInflater.inflate(LayoutInflater.java:539)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:374)
      at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
      at e.alasse.opencv.OpenCamera.onCreate(OpenCamera.java:33)
      at android.app.Activity.performCreate(Activity.java:6301)
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2519)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654) 
      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488) 
      at android.os.Handler.dispatchMessage(Handler.java:111) 
      at android.os.Looper.loop(Looper.java:207) 
      at android.app.ActivityThread.main(ActivityThread.java:5728) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
   Caused by: android.view.InflateException: Binary XML file line #20: Error inflating class ImageView
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:782)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:835)
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:515)
      at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
      at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
      at e.alasse.opencv.OpenCamera.onCreate(OpenCamera.java:33) 
      at android.app.Activity.performCreate(Activity.java:6301) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2519) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654) 
      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488) 
      at android.os.Handler.dispatchMessage(Handler.java:111) 
      at android.os.Looper.loop(Looper.java:207) 
      at android.app.ActivityThread.main(ActivityThread.java:5728) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) 
   Caused by: android.content.res.Resources$NotFoundException: Resource ID #0x7f070066
      at android.content.res.Resources.getValue(Resources.java:1544)
      at android.support.v7.widget.AppCompatDrawableManager.loadDrawableFromDelegates(AppCompatDrawableManager.java:331)
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:198)
      at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:191)
      at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:102)
      at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:59)
      at android.support.v7.widget.AppCompatImageView.&lt;init&gt;(AppCompatImageView.java:78)
      at android.support.v7.widget.AppCompatImageView.&lt;init&gt;(AppCompatImageView.java:68)
      at android.support.v7.app.AppCompatViewInflater.createImageView(AppCompatViewInflater.java:182)
      at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
      at android.support.v7.app.AppCompatDelegateImpl.createView(AppCompatDelegateImpl.java:1266)
      at android.support.v7.app.AppCompatDelegateImpl.onCreateView(AppCompatDelegateImpl.java:1316)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:746)
      at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704) 
      at android.view.LayoutInflater.rInflate(LayoutInflater.java:835) 
      at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:798) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:515) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:423) 
      at android.view.LayoutInflater.inflate(LayoutInflater.java:374) 
      at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469) 
      at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140) 
      at e.alasse.opencv.OpenCamera.onCreate(OpenCamera.java:33) 
      at android.app.Activity.performCreate(Activity.java:6301) 
      at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1113) 
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2519) 
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2654) 
      at android.app.ActivityThread.-wrap11(ActivityThread.java) 
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1488) 
      at android.os.Handler.dispatchMessage(Handler.java:111) 
      at android.os.Looper.loop(Looper.java:207) 
      at android.app.ActivityThread.main(ActivityThread.java:5728) 
      at java.lang.reflect.Method.invoke(Native Method) 
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789) 
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679) `
  </code></pre>
  
  <p>//OpenCamera.java
      package e.alasse.opencv;</p>
  
  <pre><code>import android.content.Intent;
  import android.database.Cursor;
  import android.graphics.Bitmap;
  import android.media.ExifInterface;
  import android.net.Uri;
  import android.provider.MediaStore;
  import android.support.v7.app.AppCompatActivity;
  import android.os.Bundle;
  import android.view.Display;
  import android.view.View;
  import android.widget.ImageView;
  
  import org.opencv.android.Utils;
  import org.opencv.core.Core;
  import org.opencv.core.Mat;
  import org.opencv.core.Point;
  import org.opencv.core.Size;
  import org.opencv.imgcodecs.Imgcodecs;
  import org.opencv.imgproc.Imgproc;
  
  import java.io.IOException;
  
  public class OpenCamera extends AppCompatActivity {
  
  
  ImageView iv;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_open_camera);
      iv = findViewById(R.id.imageView);
  }
  
  public void openGallery(View v) {
      Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
      startActivityForResult(intent, 101);
  }
  
  @Override
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      if (requestCode == 101 &amp;&amp; resultCode == RESULT_OK &amp;&amp; data != null) {
          Uri imageUri = data.getData();
          String path = getPath(imageUri);
          loadImage(path);
          displayImage(sampledImg);
  
  
      }
  }
  
  private void displayImage(Mat mat)
  {
      Bitmap bitmap = Bitmap.createBitmap(mat.cols(),mat.rows(),Bitmap.Config.RGB_565);
  
      //convert mat to bitmap
  
      Utils.matToBitmap(mat, bitmap);
      iv.setImageBitmap(bitmap);
  }
      Mat sampledImg;
      private void loadImage(String path) {
  
  
      Mat originalImage = Imgcodecs.imread(path);
      Mat rgbImg = new Mat();
  
      Imgproc.cvtColor(originalImage, rgbImg, Imgproc.COLOR_BGR2RGB);
      Display display = getWindowManager().getDefaultDisplay();
  
      Point size = new Point();
      display.getSize(size);
  
      int mobile_width = (int) size.x;
      int mobile_height = (int) size.y;
  
      Mat sampledImg = new Mat();
  
      double downSampleRatio = calculateSubSimpleSize(rgbImg, mobile_width, mobile_height);
      Imgproc.resize(rgbImg, sampledImg, new Size(), downSampleRatio, downSampleRatio, Imgproc.INTER_AREA);
  
      try
      {
          ExifInterface exif = new ExifInterface(path);
          int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);
  
          switch(orientation)
          {
              case ExifInterface.ORIENTATION_ROTATE_90:
                  sampledImg = sampledImg.t();
                  Core.flip(sampledImg, sampledImg, 1);
                  break;
  
              case ExifInterface.ORIENTATION_ROTATE_270:
                  sampledImg = sampledImg.t();
                  Core.flip(sampledImg, sampledImg, 0);
                  break;
          }
      } catch (IOException e) {
          e.printStackTrace();
      }
  
  }
  
  
  
  private double calculateSubSimpleSize(Mat src, int mobile_width, int mobile_height) {
  
      final int width = src.width();
      final int height = src.height();
      double inSampleSize = 1;
  
      if (height &gt; mobile_height || width &gt; mobile_width) {
  //calculate ratio
  
          final double heightRatio = (double) mobile_height / (double) height;
          final double widthRatio = (double) mobile_width / (double) width;
  
          inSampleSize = heightRatio &lt; widthRatio ? height : width;
      }
  
      return inSampleSize;
  }
  
  private String getPath(Uri uri) {
      if (uri == null) {
          return null;
  
      } else {
          String projection = (MediaStore.Images.Media.DATA);
          Cursor cursor = getContentResolver().query(uri, new String[]{projection}, null, null, null);
          if (cursor != null) {
              int col_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
              cursor.moveToFirst();
  
              return cursor.getString(col_index);
          }
  
      }
      return uri.getPath();
  }
  }
  </code></pre>
  
  <p>//activity_open_camera.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  tools:context=".OpenCamera"&gt;
  
  &lt;Button
      android:id="@+id/button"
      android:layout_width="351dp"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_centerHorizontal="true"
      android:background="@color/bgcolor"
      android:onClick="openGallery"
      android:text="Pick Image"
      android:textColor="@color/txtcolor" /&gt;
  
  &lt;ImageView
      android:id="@+id/imageView"
      android:layout_width="351dp"
      android:layout_height="562dp"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:layout_marginTop="0dp"
      android:background="@color/bgcolor"
      app:srcCompat="@drawable/ic_launcher_foreground" /&gt;
  </code></pre>
  
  <p></p>
  
  <p>//manifest</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="e.alasse.opencv"&gt;
  
  &lt;uses-permission android:name="android.permission.CAMERA" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@mipmap/ic_launcher"
      android:label="@string/app_name"
      android:roundIcon="@mipmap/ic_launcher_round"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"&gt;
      &lt;activity android:name=".OpenCamera"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity android:name= ".MainActivity"/&gt;
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>