0

I get NullPointerException on some devices (HTC Desire 510), but I have no idea why. Here's my code:

private String captureFilePath;  

private boolean captureVideo(){
    if (!MediaUtils.isIntentAvailable(this, MediaStore.ACTION_VIDEO_CAPTURE))
        return false;
    File capturedFile = FileUtils.getNewVideoPath(false);
    capturedFilePath = capturedFile.getAbsolutePath();
    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    //     capturedFilePath NOT NULL
    //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    if(capturedFilePath==null)
        Log.d(TAG, "1. capturedFilePath == null");
    Intent video = new Intent(MediaStore.ACTION_VIDEO_CAPTURE);
    video.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(capturedFile));
    startActivityForResult(video, VIDEO_CAPTURE_REQUEST);
    return true;
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if(resultCode != Activity.RESULT_OK)
        return;
    switch (requestCode) {
        case VIDEO_CAPTURE_REQUEST:
            builder = Media.newBuilder();
            //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            //       capturedFilePath NULL
            //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
            if(capturedFilePath==null)
                Log.d(TAG, "2. capturedFilePath == null");
            // Exception
            File capturedFile = new File(capturedFilePath);
            //...
    }
}

Why does variable capturedFilePath become null? Video saved on external storage is in right place, but I can't pick up it.

Not all devices produce this error (in example Lenovo S860 doesn't) and not always.

Gogi Bobina
  • 1,086
  • 1
  • 8
  • 25
  • Yet another manifestation of *[Android: Activity getting Destroyed after calling Camera Intent](http://stackoverflow.com/questions/16014930/android-activity-getting-destroyed-after-calling-camera-intent)* – Alex Cohn Oct 20 '15 at 14:42
  • 1
    @AlexCohn thank you! it works – Gogi Bobina Oct 20 '15 at 15:59

0 Answers0