获取java.lang.IllegalArgumentException:指定为非null的参数为null,在Kotlin中使用Camera Intent,但是在JAVA中,此代码有效。 我很困惑为什么会这样。
捕获图像后,出现此错误并使应用崩溃。
try {
val imageFile = createImageFile()
val callCameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
if(callCameraIntent.resolveActivity(packageManager) != null) {
val authorities = packageName + ".provider"
val imageUri = FileProvider.getUriForFile(this, authorities, imageFile)
callCameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri)
startActivityForResult(callCameraIntent, CAMERA_REQUEST_CODE)
}
} catch (e: IOException) {
Toast.makeText(this, "Could not create file!", Toast.LENGTH_SHORT).show()
}
fun createImageFile(): File {
val timeStamp: String = SimpleDateFormat("yyyyMMdd_HHmmss").format(Date())
val imageFileName: String = "JPEG_" + timeStamp + "_"
val storageDir: File = getExternalFilesDir(Environment.DIRECTORY_PICTURES)
if(!storageDir.exists()) storageDir.mkdirs()
val imageFile = File.createTempFile(imageFileName, ".jpg", storageDir)
imageFilePath = imageFile.absolutePath
return imageFile
}
09-30 13:32:19.145 6918-6918/app.smallbites.com.smallbites E/AndroidRuntime: FATAL EXCEPTION: main
Process: app.smallbites.com.smallbites, PID: 6918
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1001, result=-1, data=null} to activity {app.smallbites.com.smallbites/app.smallbites.com.smallbites.ui.onboarding.AddKidActivity}: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter data
at android.app.ActivityThread.deliverResults(ActivityThread.java:4268)
at android.app.ActivityThread.handleSendResult(ActivityThread.java:4312)
at android.app.ActivityThread.-wrap19(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1644)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6501)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Caused by: java.lang.IllegalArgumentException: Parameter specified as non-null is null: method kotlin.jvm.internal.Intrinsics.checkParameterIsNotNull, parameter data
at app.smallbites.com.smallbites.ui.onboarding.AddKidActivity.onActivityResult(Unknown Source:37)
答案 0 :(得分:0)
问题出在您要传输的数据上。您将 Null 对象放置为 NonNull
检查接下来的事情:
另外,请检查您的问题是否存在。我想我发现了类似的问题。