gpt4 book ai didi

java - java.lang.IllegalArgumentException 导致指定为非 null 的参数为 null

转载 作者:行者123 更新时间:2023-12-02 03:01:42 25 4
gpt4 key购买 nike

拍照并单击相机界面上的复选标记按钮后,出现以下导致应用崩溃的异常:

Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter data

仅当我尝试拍照时才会出现此异常,而当我从图库中选择图像时不会出现此异常。

异常表明 data 参数作为 null 传递,而它应该是 non-null 并指向 kotlin 文件功能。研究这个问题后,我发现我需要将 ? 传递给上述参数。 (来源:thisthis),但现在我得到了

Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable receiver of type Intent?

我没有使用 Kotlin 的经验,所以不确定这对我来说是否是正确的解决方案。如果有人遇到过这样的异常,我想知道如何解决这个问题。

代码如下:

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);
}
});
});
}

异常日志:

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

主要 Activity 代码:

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")
}
}
}

最佳答案

更改 onActivityResult 方法的签名,如下所示:

覆盖 fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {}

这将解决问题。 data 可以为 null,但您将其声明为 non-null

<小时/>

编辑:

然后,在函数主体中,确保在检索字符串时检查是否为空:

if(resultCode == Activity.RESULT_OK) {
sendStringMessageToFlutter(data?.getStringExtra("roomName") ?: "default_value_when_null", "completeRoom")
}

关于java - java.lang.IllegalArgumentException 导致指定为非 null 的参数为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55686816/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com