private lateinit var main: MainActivity
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_regions)
main = MainActivity()
}
On create method
override fun onActivityResult(
requestCode: Int,
resultCode: Int,
data: Intent?
) {
super.onActivityResult(requestCode, resultCode, data)
if (requestCode == MainActivity2.SCREEN_RECORD_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
//Set file path or Uri depending on SDK version
main.setOutputPath()
//Start screen recording
hbRecorder.startScreenRecording(data, resultCode, this)
}
}
}
here is my Kotlin method, main is my Java Classes object and I am trying to call the setOutPath Method but when I run the program it gives 'android.content.ContentResolver android.content.Context.getContentResolver()' on a null object reference error
ContentResolver resolver;
ContentValues contentValues;
Uri mUri;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public void setOutputPath() {
String filename = generateFileName();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
resolver = getContentResolver();
contentValues = new ContentValues();
contentValues.put(MediaStore.Video.Media.RELATIVE_PATH, "Movies/" + "HBRecorder");
contentValues.put(MediaStore.Video.Media.TITLE, filename);
contentValues.put(MediaStore.MediaColumns.DISPLAY_NAME, filename);
contentValues.put(MediaStore.MediaColumns.MIME_TYPE, "video/mp4");
mUri = resolver.insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, contentValues);
//FILE NAME SHOULD BE THE SAME
hbRecorder.setFileName(filename);
hbRecorder.setOutputUri(mUri);
}else{
createFolder();
hbRecorder.setOutputPath(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES) +"/HBRecorder");
}
}
here is my java method. It gives me an error on this line.
resolver = getContentResolver();