Home » Android » Error inflating class <unknown> – app crashes

Error inflating class <unknown> – app crashes

Posted by: admin November 1, 2017 Leave a comment

Questions:

In an Android app that I developed, the app crashes when I move to a certain activity. I saw that many people encountered a similar problem before, but none of the former answers solve my problem.

Here’s the relevant code:

StillsActivity.java

the code crashes on the last line of this snippet

public class StillsActivity extends SpatialFilteringActivity {

    private static final int SELECT_PICTURE = 1;
    private static final String TAG = "Stills";

    private Uri mURI;
    private Bitmap mBitmap;
    private ImageView mImageView;
    private Mat mImToProcess = new Mat();
    private Mat mImGray = new Mat();
    private Mat mFilteredImage = new Mat();

    private SeekBar mSeekBarSpatial;
    private SeekBar mSeekBarIntensity;
    private SeekBar mSeekBarAlpha;
    private SeekBar mSeekBarBeta;
    private TextView mTextViewSpatial;
    private TextView mTextViewIntensity;
    private TextView mTextViewAlpha;
    private TextView mTextViewBeta;
    private MenuItem mSelectedItem;


    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent
            data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == SELECT_PICTURE) {
            if (resultCode == RESULT_OK) {
                mURI = data.getData();
                if (mURI != null) {
                    try {
                        mBitmap = Util.getBitmap(this, mURI);
                        mImageView.setImageBitmap(Util.getResizedBitmap(mBitmap,
                                1000));
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_stills);

// APP CRASHES HERE

        mImageView = (ImageView) findViewById(R.id.imageView1);


        Button loadButton = (Button) findViewById(R.id.loadButton);
        loadButton.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("SimpleDateFormat")
            @Override
            public void onClick(View v) {

                Log.i(TAG, "onClick event");
                Intent intent = new Intent();
                intent.setType("image/*");
                intent.setAction(Intent.ACTION_GET_CONTENT);
                startActivityForResult(Intent.createChooser(intent, "Select an image"), SELECT_PICTURE);

            }
        });

        mSeekBarSpatial = (SeekBar) findViewById(R.id.seekBarSpatial);
        mTextViewSpatial = (TextView) findViewById(R.id.sigmaSpatialTextView);
        setSeekBar(mSeekBarSpatial, mTextViewSpatial, getResources().getString(R.string.stringSpatial), MyImageProc.SIGMA_SPATIAL_MAX);
        mSeekBarIntensity = (SeekBar) findViewById(R.id.seekBarIntensity);
        mTextViewIntensity = (TextView) findViewById(R.id.sigmaIntensityTextView);
        setSeekBar(mSeekBarIntensity, mTextViewIntensity, getResources().getString(R.string.stringIntensity), MyImageProc.SIGMA_INTENSITY_MAX);

        mSeekBarAlpha = (SeekBar) findViewById(R.id.seekBarAlpha);
        mTextViewAlpha = (TextView) findViewById(R.id.alphaTextView);
        setSeekBar(mSeekBarAlpha, mTextViewAlpha, getResources().getString(R.string.stringAlpha), MyImageProc.ALPHA_MAX);
        mSeekBarBeta = (SeekBar) findViewById(R.id.seekBarBeta);
        mTextViewBeta = (TextView) findViewById(R.id.betaTextView);
        setSeekBar(mSeekBarBeta, mTextViewBeta, getResources().getString(R.string.stringBeta), MyImageProc.BETA_MAX);
    }

// etc.

SpatialFilteringActivity.java

public class SpatialFilteringActivity extends AppCompatActivity {

    private static final String TAG = "SpatialFiltering";

    //menu members
    private SubMenu mResolutionSubMenu;
    private SubMenu mCameraSubMenu;

    //flags
    private Boolean mSettingsMenuAvailable =false;

    protected static final int SETTINGS_GROUP_ID = 1;
    protected static final int RESOLUTION_GROUP_ID = 2;
    protected static final int CAMERA_GROUP_ID = 3;
    protected static final int DEFAULT_GROUP_ID = 4;
    protected static final int COLOR_GROUP_ID = 5;
    protected static final int FILTER_GROUP_ID = 6;
    protected static final int STILL_GROUP_ID = 7;

    private MyJavaCameraView mOpenCvCameraView;

    private CameraListener mCameraListener = new CameraListener();

    private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(this) {
        @Override
        public void onManagerConnected(int status) {
            switch (status) {
                case LoaderCallbackInterface.SUCCESS:
                    Log.i(TAG, "OpenCV loaded successfully");
                    mOpenCvCameraView.enableView();
                    break;
                default:
                    super.onManagerConnected(status);
                    break;
            }
        }
    };

    private String[] mCameraNames = {"Front", "Rear"};
    private int[] mCameraIDarray = {CameraBridgeViewBase.CAMERA_ID_FRONT, CameraBridgeViewBase.CAMERA_ID_BACK};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_spatial_filtering);

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

        mOpenCvCameraView = (MyJavaCameraView) findViewById(R.id.Java_Camera_View);
        mOpenCvCameraView.setCameraIndex(CameraBridgeViewBase.CAMERA_ID_ANY);
        mOpenCvCameraView.setVisibility(SurfaceView.VISIBLE);
        mOpenCvCameraView.setCvCameraViewListener(mCameraListener);
        Button saveButton = (Button) findViewById(R.id.saveButton);
        saveButton.setOnClickListener(new View.OnClickListener() {
            @SuppressLint("SimpleDateFormat")
            @Override
            public void onClick(View v) {

                Log.i(TAG, "onClick event");
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
                String currentDateandTime = sdf.format(new Date());
                String fileName = Environment.getExternalStorageDirectory().getPath() +
                        "/sample_picture_" + currentDateandTime + ".jpg";
                mOpenCvCameraView.takePicture(fileName);
                addImageToGallery(fileName, SpatialFilteringActivity.this);
                Toast.makeText(SpatialFilteringActivity.this, fileName + " saved",
                        Toast.LENGTH_SHORT).show();

            }
        });

    }
    //etc.

activity_stills.xml

<?xml version="1.0" encoding="utf-8"?>
<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:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                android:paddingBottom="@dimen/activity_vertical_margin"
                tools:context="il.ac.tau.adviplab.iplab2_hn.StillsActivity">
    <ImageView
        android:contentDescription="@string/desc"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView1"
        android:layout_marginLeft="30dp"
        android:layout_marginRight="30dp"
        android:src="@drawable/loadimage"
        android:adjustViewBounds="true"
        android:layout_centerVertical="true"/>
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/load_button"
        android:id="@+id/loadButton"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"/>

    <SeekBar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/seekBarSpatial"
        android:layout_marginTop="13dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"
        android:layout_alignLeft="@+id/sigmaSpatialTextView"
        android:layout_alignStart="@+id/sigmaSpatialTextView"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="8dp"
        android:id="@+id/sigmaSpatialTextView"
        android:text="@string/stringSpatial"
        android:layout_below="@+id/seekBarSpatial"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true"/>
    <SeekBar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/seekBarIntensity"
        android:layout_marginTop="15dp"
        android:layout_below="@+id/sigmaSpatialTextView"
        android:layout_alignLeft="@+id/sigmaSpatialTextView"
        android:layout_alignStart="@+id/sigmaSpatialTextView"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:id="@+id/sigmaIntensityTextView"
        android:text="@string/stringIntensity"
        android:layout_below="@+id/seekBarIntensity"
        android:layout_alignLeft="@+id/seekBarIntensity"
        android:layout_alignStart="@+id/seekBarIntensity"/>


    <SeekBar
        android:id="@+id/seekBarAlpha"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="16dp"
        android:layout_below="@+id/sigmaIntensityTextView"
        android:layout_alignLeft="@+id/alphaTextView"
        android:layout_alignStart="@+id/alphaTextView"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/alphaTextView"
        android:text="@string/stringAlpha"
        android:layout_marginTop="12dp"
        android:layout_below="@+id/seekBarAlpha"
        android:layout_alignLeft="@+id/sigmaIntensityTextView"
        android:layout_alignStart="@+id/sigmaIntensityTextView"/>
    <SeekBar
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/seekBarBeta"
        android:layout_marginTop="8dp"
        android:layout_below="@+id/alphaTextView"
        android:layout_alignLeft="@+id/alphaTextView"
        android:layout_alignStart="@+id/alphaTextView"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/betaTextView"
        android:text="@string/stringBeta"
        android:layout_below="@+id/seekBarBeta"
        android:layout_alignLeft="@+id/seekBarBeta"
        android:layout_alignStart="@+id/seekBarBeta"/>

</RelativeLayout>

note: the @drawable/loadimage is 1000*978 pixels, if that matters

Logs

I’d appreciate any help.

Thanks!

Answers:

Please follow background image size

For Supported device