Reputation: 11659
After I take a picture and click checkmark
button on camera interface, I get below exception that leads to app crash:
Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter data
This exception occurs only if I try to take a picture, not when I select an image from the gallery.
As the exception states that the data
parameter is being passed as null
whereas it should be non-null
and points to the kotlin file function. After researching on this issue, I came to know that I need to pass ?
to the said parameter. (Source : this and this), but now I am getting
Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Intent?
I have no experience of working with Kotlin so am not sure if that was the correct fix in my case. I would like to know how to fix this issue if anybody has come across an exception like this.
Code below:
void _checkCameraPermission() {
PermissionHandler()
.checkPermissionStatus(PermissionGroup.camera)
.then((status) {
if (status == PermissionStatus.granted) {
getImage(ImageSource.camera);
} else {
_askCameraPermission();
}
});
}
void _askCameraPermission() {
PermissionHandler()
.requestPermissions([PermissionGroup.camera]).then(_onStatusRequested);
}
void _onStatusRequested(Map<PermissionGroup, PermissionStatus> value) {
final status = value[PermissionGroup.camera];
if (status == PermissionStatus.granted) {
getImage(ImageSource.camera);
}
}
Future uploadFile(imageFile) async {
// String fileName = DateTime.now().millisecondsSinceEpoch.toString();
String fileName = "images/" + new Uuid().v4() + ".jpg";
StorageReference reference = FirebaseStorage.instance.ref().child(fileName);
StorageUploadTask uploadTask = reference.putFile(imageFile);
await uploadTask.onComplete.then((value) {
reference.getDownloadURL().then((result) {
// result is the file URL
if (result != null) {
setState(() {
isLoading = false;
});
onSendMessage(result, 2);
}
});
});
}
Exception log:
E/AndroidRuntime( 8402): FATAL EXCEPTION: main
E/AndroidRuntime( 8402): Process: com.quickcarl.qcflutterpro, PID: 8402
E/AndroidRuntime( 8402): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2343, result=-1, data=null} to activity {com.quickcarl.qcflutterpro/com.quickcarl.qcflutterpro.MainActivity}: **java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter data**
E/AndroidRuntime( 8402): at android.app.ActivityThread.deliverResults(ActivityThread.java:3699)
E/AndroidRuntime( 8402): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3742)
E/AndroidRuntime( 8402): at android.app.ActivityThread.-wrap16(ActivityThread.java)
E/AndroidRuntime( 8402): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1393)
E/AndroidRuntime( 8402): at android.os.Handler.dispatchMessage(Handler.java:102)
E/AndroidRuntime( 8402): at android.os.Looper.loop(Looper.java:148)
E/AndroidRuntime( 8402): at android.app.ActivityThread.main(ActivityThread.java:5417)
E/AndroidRuntime( 8402): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 8402): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
E/AndroidRuntime( 8402): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
E/AndroidRuntime( 8402): Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter data
E/AndroidRuntime( 8402): at com.quickcarl.qcflutterpro.MainActivity.onActivityResult(MainActivity.kt)
E/AndroidRuntime( 8402): at android.app.Activity.dispatchActivityResult(Activity.java:6428)
E/AndroidRuntime( 8402): at android.app.ActivityThread.deliverResults(ActivityThread.java:3695)
E/AndroidRuntime( 8402): ... 9 more
MainActivity code:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
if(requestCode == VIDEO_SCREEN_REQUEST_CODE) {
if(resultCode == Activity.RESULT_OK) {
sendStringMessageToFlutter(data.getStringExtra("roomName"), "completeRoom")
}
}
}
Upvotes: 1
Views: 5495
Reputation: 2407
Change the signature of the onActivityResult
method as follow:
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {}
This will fix the problem. data
can be null but you're declaring it as non-null
EDIT:
Then, in the body of the function, be sure to check for nullability when retrieving the string:
if(resultCode == Activity.RESULT_OK) {
sendStringMessageToFlutter(data?.getStringExtra("roomName") ?: "default_value_when_null", "completeRoom")
}
Upvotes: 4