与持久性和查询相关的Firebase runloop(3.0.0)中未捕获的异常

时间:2016-07-05 17:01:47

标签: android firebase firebase-realtime-database

我已经在这个异常中苦苦挣扎了一段时间。 firebase组中的相关主题有点死https://groups.google.com/forum/#!topic/firebase-talk/iy0762S3KsU,另外两个与SO相关的帖子未得到答复:Uncaught exception in Firebase runloop (3.0.0)Uncaught exception in Firebase runloop (3.0.0). Please report to support@firebase.com

关闭数据库持久性的解决方法是有效的,但对于需要离线功能的应用程序而言,这并不是不可接受的。

我准备了一个最小的活动示例,它在我的环境中重现了异常。这一切都归结为使用查询读取数据库。它足以启动和终止(从Android Studio“终止”,而不仅仅是退出)活动3次(奇怪),并且在第3次启动时它会崩溃,并伴随着以下一系列异常(排队的查询越多,我认为的例外就越多) ):

07-05 18:47:10.132 20291-20291/com.mypackage D/ChimeraFileApk: Classloading successful. Optimized code found.
07-05 18:47:10.154 20291-20381/com.mypackage E/RunLoop: Uncaught exception in Firebase runloop (3.0.0). Please report to support@firebase.com
                                                           java.lang.AssertionError: hardAssert failed: 
                                                               at com.google.android.gms.internal.zzaiv.zzb(Unknown Source)
                                                               at com.google.android.gms.internal.zzaiv.zzaN(Unknown Source)
                                                               at com.google.android.gms.internal.zzagh.zzb(Unknown Source)
                                                               at com.google.android.gms.internal.zzagh.<init>(Unknown Source)
                                                               at com.google.android.gms.internal.zzaga.<init>(Unknown Source)
                                                               at com.google.android.gms.internal.zzaga.<init>(Unknown Source)
                                                               at com.google.android.gms.internal.zzadp.zza(Unknown Source)
                                                               at com.google.android.gms.internal.zzaeu.zzic(Unknown Source)
                                                               at com.google.android.gms.internal.zzafc.zzRy(Unknown Source)
                                                               at com.google.android.gms.internal.zzafc.zza(Unknown Source)
                                                               at com.google.android.gms.internal.zzafc$1.run(Unknown Source)
                                                               at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                               at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                               at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                               at java.lang.Thread.run(Thread.java:818)
07-05 18:47:10.154 20291-20291/com.mypackage D/AndroidRuntime: Shutting down VM
07-05 18:47:10.155 20291-20291/com.mypackage E/AndroidRuntime: FATAL EXCEPTION: main
                                                                  Process: com.mypackage, PID: 20291
                                                                  java.lang.RuntimeException: Uncaught exception in Firebase runloop (3.0.0). Please report to support@firebase.com
                                                                      at com.google.android.gms.internal.zzadp$1$1.run(Unknown Source)
                                                                      at android.os.Handler.handleCallback(Handler.java:739)
                                                                      at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                      at android.os.Looper.loop(Looper.java:148)
                                                                      at android.app.ActivityThread.main(ActivityThread.java:5417)
                                                                      at java.lang.reflect.Method.invoke(Native Method)
                                                                      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
                                                                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
                                                                   Caused by: java.lang.AssertionError: hardAssert failed: 
                                                                      at com.google.android.gms.internal.zzaiv.zzb(Unknown Source)
                                                                      at com.google.android.gms.internal.zzaiv.zzaN(Unknown Source)
                                                                      at com.google.android.gms.internal.zzagh.zzb(Unknown Source)
                                                                      at com.google.android.gms.internal.zzagh.<init>(Unknown Source)
                                                                      at com.google.android.gms.internal.zzaga.<init>(Unknown Source)
                                                                      at com.google.android.gms.internal.zzaga.<init>(Unknown Source)
                                                                      at com.google.android.gms.internal.zzadp.zza(Unknown Source)
                                                                      at com.google.android.gms.internal.zzaeu.zzic(Unknown Source)
                                                                      at com.google.android.gms.internal.zzafc.zzRy(Unknown Source)
                                                                      at com.google.android.gms.internal.zzafc.zza(Unknown Source)
                                                                      at com.google.android.gms.internal.zzafc$1.run(Unknown Source)
                                                                      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                                      at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                      at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                                      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                      at java.lang.Thread.run(Thread.java:818)
07-05 18:47:10.165 20291-20381/com.mypackage E/RunLoop: Uncaught exception in Firebase runloop (3.0.0). Please report to support@firebase.com
                                                           java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.google.android.gms.internal.zzafj.zzg(com.google.android.gms.internal.zzaew)' on a null object reference
                                                               at com.google.android.gms.internal.zzafc.zzf(Unknown Source)
                                                               at com.google.firebase.database.Query$3.run(Unknown Source)
                                                               at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                               at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                               at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                               at java.lang.Thread.run(Thread.java:818)
07-05 18:47:10.166 20291-20381/com.mypackage E/RunLoop: Uncaught exception in Firebase runloop (3.0.0). Please report to support@firebase.com
                                                           java.lang.NullPointerException: Attempt to invoke virtual method 'java.util.List com.google.android.gms.internal.zzafj.zzg(com.google.android.gms.internal.zzaew)' on a null object reference
                                                               at com.google.android.gms.internal.zzafc.zzf(Unknown Source)
                                                               at com.google.firebase.database.Query$3.run(Unknown Source)
                                                               at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                               at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                               at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                               at java.lang.Thread.run(Thread.java:818)
07-05 18:47:10.173 20291-20381/com.mypackage E/RunLoop: Uncaught exception in Firebase runloop (3.0.0). Please report to support@firebase.com
                                                           java.lang.NullPointerException: Attempt to invoke virtual method 'void com.google.android.gms.internal.zzafg.zzg(com.google.android.gms.internal.zzafa, com.google.android.gms.internal.zzahu)' on a null object reference
                                                               at com.google.android.gms.internal.zzafc.zzb(Unknown Source)
                                                               at com.google.android.gms.internal.zzafc.zza(Unknown Source)
                                                               at com.google.android.gms.internal.zzafc.zzaO(Unknown Source)
                                                               at com.google.firebase.database.connection.idl.IPersistentConnectionImpl$3.zzaO(Unknown Source)
                                                               at com.google.firebase.database.connection.idl.zzi$zza.onTransact(Unknown Source)
                                                               at android.os.Binder.transact(Binder.java:387)
                                                               at alx.a(:com.google.android.gms.DynamiteModulesC:196)
                                                               at amb.a(:com.google.android.gms.DynamiteModulesC:330)
                                                               at akh.a(:com.google.android.gms.DynamiteModulesC:3591)
                                                               at amf.a(:com.google.android.gms.DynamiteModulesC:386)
                                                               at aln.onTransact(:com.google.android.gms.DynamiteModulesC:50)
                                                               at android.os.Binder.transact(Binder.java:387)
                                                               at com.google.firebase.database.connection.idl.zzf$zza$zza.zzhT(Unknown Source)
                                                               at com.google.firebase.database.connection.idl.IPersistentConnectionImpl$5$1.zzhT(Unknown Source)
                                                               at com.google.android.gms.internal.zzaeu$1$1.zzhT(Unknown Source)
                                                               at com.google.android.gms.internal.zzadn$1.onFailure(Unknown Source)
                                                               at com.google.android.gms.tasks.zzd$1.run(Unknown Source)
                                                               at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                               at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                               at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                               at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                               at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                               at java.lang.Thread.run(Thread.java:818)
07-05 18:47:11.745 20291-20291/com.mypackage I/Process: Sending signal. PID: 20291 SIG: 9

崩溃是在获取对数据库的引用并设置持久性完成后首次尝试读取。

这是活动:

public class TestRunloopException extends AppCompatActivity {

    private static final String TAG = "test";
    private Handler mHandler = new Handler();

    Runnable mReadScoresRunnable = new Runnable() {
        @Override
        public void run() {
            readScores();
            mHandler.postDelayed(mReadScoresRunnable, 5000);
        }
    };

    @Override
    protected void onStart() {
        super.onStart();
        mHandler.postDelayed(mReadScoresRunnable, 3000);
    }

    void readScores() {
        DatabaseReference scoresRef = getDatabase().getReference("scores");
       //it occurs even with a single query..
       //scoresRef.startAt(51).limitToFirst(3).addListenerForSingleValueEvent(new MyValueListener());
        scoresRef.endAt(50).limitToLast(4).addListenerForSingleValueEvent(new MyValueListener());
    }


    public static class MyValueListener implements ValueEventListener {
        @Override
        public void onDataChange(DataSnapshot data) {
            Log.d(TAG, "onDataChange: " + data.getValue());
        }

        @Override
        public void onCancelled(DatabaseError error) {
            Log.d(TAG, "onCancelled: " + error.getMessage());
        }
    }


    // access-wrapper, set persistence only once
    private static FirebaseDatabase mDatabase;
    public static FirebaseDatabase getDatabase() {
        if (mDatabase == null) {
            mDatabase = FirebaseDatabase.getInstance();
            mDatabase.setPersistenceEnabled(true);
        }
        return mDatabase;
    }

}

“得分”节点没有特定的安全设置:"scores": { ".read": true, ".write": true } ...

使用firebase测试 - *:9.0.2,但在9.2.0中也观察到了该错误。

如何在同一参考/节点上使用多个查询时避免崩溃,当然还有持久性?

2 个答案:

答案 0 :(得分:0)

唯一适用于我的解决方案是两次连续调用Event Listener。

scoresRef.endAt(50).limitToLast(4).addListenerForSingleValueEvent(new MyValueListener());
scoresRef.endAt(50).limitToLast(4).addListenerForSingleValueEvent(new MyValueListener());

答案 1 :(得分:0)

我遇到了同样的问题,我只修复了build.gradle(应用程序模块)上的firebase-core和firebase-database版本

dependencies {
  ... 
  implementation 'com.google.firebase:firebase-core:17.1.0'
  implementation 'com.google.firebase:firebase-database:19.0.0'
}

您可以检查您在https://firebase.google.com/support/release-notes/android上是否具有当前版本