Q:

OpenCV4Android take still images

I am using the code below to capture still images using OnTouch event but my app crashes as soon as I touch:
public boolean onTouch(View v, MotionEvent event) {
    Log.i(TAG,"onTouch event");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
    String currentDateandTime = sdf.format(new Date());
    String fileName = Environment.getExternalStorageDirectory().getPath() +
            "/DCIM/app/sample_picture_" + currentDateandTime + ".jpg";
    Toast.makeText(this, fileName + " saved", Toast.LENGTH_SHORT).show();
    Imgcodecs.imwrite(fileName,mRgba);
    return false;
}

I am new to opencv. Thanks for help!

A:

Finally I found the problem! mRgba was not initialized in onCameraViewStarted().
public boolean onTouch(View v, MotionEvent event) {
    Log.i(TAG,"onTouch event");
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss");
    String currentDateandTime = sdf.format(new Date());
    String fileName = Environment.getExternalStorageDirectory().getPath() +
            "/DCIM/app/sample_picture_" + currentDateandTime + ".jpg";
    Toast.makeText(this, fileName + " saved", Toast.LENGTH_SHORT).show();
    Imgcodecs.imwrite(fileName, mIntermediateMat);
    return false;
}

