Jetpack 的 BiometricPrompt (androidx.biometric.BiometricPrompt) 抛出 NullPointerException

Jetpack's BiometricPrompt (androidx.biometric.BiometricPrompt) throws NullPointerException

我在测试项目中使用 androidx.biometric:biometric:1.0.0-alpha03,在推送 negative button 时,我总是收到以下错误消息:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.CharSequence androidx.biometric.BiometricFragment.getNegativeButtonText()' on a null object reference
    at androidx.biometric.BiometricPrompt.run(BiometricPrompt.java:329)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
    at java.lang.Thread.run(Thread.java:764)

我认为这是一个需要修复的库问题,因为该片段似乎为空,或者我在这里做错了什么?

val prompt = BiometricPrompt(activity, Executors.newSingleThreadExecutor(), object : BiometricPrompt.AuthenticationCallback() {
        override fun onAuthenticationError(errorCode: Int, errString: CharSequence) {}
        override fun onAuthenticationSucceeded(result: BiometricPrompt.AuthenticationResult) {}
        override fun onAuthenticationFailed() {}
})

val promptInfo = BiometricPrompt.PromptInfo.Builder()
        .setTitle(title)
        .setSubtitle(subtitle)
        .setDescription(description)
        .setNegativeButtonText(activity.getString(android.R.string.cancel))
        .build()

prompt.authenticate(promptInfo)

已报告 three months ago as a bug, and it was reported as fixed two months ago。然而,他们还没有出新的神器。

该问题中的一些评论表明 "it's a timing thing",添加延迟可以作为一种解决方法。