Firebase AsyncTask致命异常

时间:2019-06-28 06:43:52

标签: firebase kotlin indexoutofboundsexception

在我的项目中,我运行 Firebase 有时(并非每次)都在运行应用程序时遇到异常:java.lang.ArrayIndexOutOfBoundsException: length=15; index=15。我不知道为什么,但是我认为它可能与Firebase有关。我的完整日志:

E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #1
Process: pl.project.project, PID: 21825
java.lang.ArrayIndexOutOfBoundsException: length=15; index=15
    at java.util.ArrayList.add(ArrayList.java:468)
    at com.facebook.appevents.RestrictiveDataManager.updateFromSetting(RestrictiveDataManager.java:46)
    at com.facebook.internal.FetchedAppSettingsManager.parseAppSettingsFromJSON(FetchedAppSettingsManager.java:323)
    at com.facebook.internal.FetchedAppSettingsManager.queryAppSettings(FetchedAppSettingsManager.java:286)
    at com.facebook.UserSettingsManager$1.run(UserSettingsManager.java:151)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    at java.lang.Thread.run(Thread.java:764)

我的飞溅活动:

class SplashActivity : AppCompatActivity() {

    private lateinit var presenter: SplashPresenter

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
        presenter = SplashPresenterImpl(this)
        presenter.onCreate()
        window.setExitTransition(null)
    }

}

SplashPresenterImpl:

class SplashPresenterImpl(val activity: SplashActivity): SplashPresenter {

    override fun onCreate() {
        val auth = FirebaseAuth.getInstance()
        if(auth.currentUser !=null && !auth.currentUser?.isEmailVerified!!) auth.signOut()
        if(auth.currentUser!=null) Handler().postDelayed({startMainActivity()},500)
        else Handler().postDelayed({startLoginActivity()},500)
    }

    private fun startMainActivity() = activity.startActivity(Intent(activity, MainActivity::class.java))

    private fun startLoginActivity(){
        val activityOptions = ActivityOptions.makeSceneTransitionAnimation(activity,
            Pair(activity.konkurlyText, "konkurlyTextTranstion"))
        activity.startActivity(Intent(activity, LoginActivity::class.java), activityOptions.toBundle())
    }   
}

预先感谢,祝您愉快。

2 个答案:

答案 0 :(得分:0)

该异常意味着在代码的某个位置存在一个数组,该数组限制为15个索引。但是您不止如此。

在Kotlin中,该数组可能不会被命名为Array。必须在后台使用一些Java代码来处理Arrays。

首先,您可以考虑减少"konkurlyTextTranstion"

中的字符数

最好的问候, 祝你好运。

答案 1 :(得分:0)

对我来说,从com.google.firebase:firebase-core:16.0.9'升级到'com.google.firebase:firebase-core:17.0.0'似乎可以解决问题。