我需要一点帮助!我正在尝试使用Facebook登录,但出现此错误,但无法成功。
> java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=-1, data=Intent { (has extras) }} to activity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
mAuth = FirebaseAuth.getInstance()
}
fun fbClicked(view: View) {
facebookButton = findViewById<View>(R.id.facebookButton) as Button?
// Initialize Facebook Login button
mCallbackManager = CallbackManager.Factory.create()
facebookButton!!.setOnClickListener(View.OnClickListener {
facebookButton!!.setEnabled(false)
LoginManager.getInstance().logInWithReadPermissions(this@MainActivity, Arrays.asList("email", "public_profile"))
LoginManager.getInstance().registerCallback(mCallbackManager, object : FacebookCallback<LoginResult> {
override fun onSuccess(loginResult: LoginResult) {
Log.d(TAG, "facebook:onSucess$loginResult")
handleFacebookAccessToken(loginResult.accessToken)
}
override fun onCancel() {
}
override fun onError(error: FacebookException) {
Log.d(TAG, "facebook:onError", error)
}
})
})
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
super.onActivityResult(requestCode, resultCode, data)
// Pass the activity result back to the Facebook SDK
mCallbackManager!!.onActivityResult(requestCode, resultCode, data)
}
private fun handleFacebookAccessToken(token: AccessToken) {
Log.d(TAG, "handleFacebookAccessToken:$token")
val credential = FacebookAuthProvider.getCredential(token.token)
mAuth!!.signInWithCredential(credential)
.addOnCompleteListener(this) { task ->
if (task.isSuccessful) {
// Sign in success, update UI with the signed-in user's information
Log.d(TAG, "signInWithCredential:success")
val user = mAuth!!.getCurrentUser()
val intent = Intent(this, InitActivity::class.java)
startActivity(intent)
facebookButton!!.setEnabled(false)
} else {
// If sign in fails, display a message to the user.
Log.w(TAG, "signInWithCredential:failure", task.exception)
Toast.makeText(this@MainActivity, "Authentication failed.",
Toast.LENGTH_SHORT).show()
facebookButton!!.setEnabled(true)
}
}
}
}
就是这样。在设法将Facebook与该应用程序连接之前,但是这次,我不知道为什么,它给出了空指针异常的错误。
这是错误
09-23 12:33:23.139 8000-8000/com.juny.repartilhe E/AndroidRuntime: FATAL EXCEPTION: main Process: com.juny.repartilhe, PID: 8000 java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=64206, result=-1, data=Intent { (has extras) }} to activity {com.juny.repartilhe/com.juny.repartilhe.MainActivity}: kotlin.KotlinNullPointerException at android.app.ActivityThread.deliverResults(ActivityThread.java:4067) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4110) at android.app.ActivityThread.access$1400(ActivityThread.java:177) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1498) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5951) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195) Caused by: kotlin.KotlinNullPointerException at com.juny.repartilhe.MainActivity$fbClicked$1$1.onSuccess(MainActivity.kt:74) at com.juny.repartilhe.MainActivity$fbClicked$1$1.onSuccess(MainActivity.kt:71) at com.facebook.login.LoginManager.finishLogin(LoginManager.java:659) at com.facebook.login.LoginManager.onActivityResult(LoginManager.java:245) at com.facebook.login.LoginManager$1.onActivityResult(LoginManager.java:174) at com.facebook.internal.CallbackManagerImpl.onActivityResult(CallbackManagerImpl.java:92) at com.juny.repartilhe.MainActivity.onActivityResult(MainActivity.kt:102) at android.app.Activity.dispatchActivityResult(Activity.java:6549) at android.app.ActivityThread.deliverResults(ActivityThread.java:4063) at android.app.ActivityThread.handleSendResult(ActivityThread.java:4110) at android.app.ActivityThread.access$1400(ActivityThread.java:177) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1498) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5951) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)