尝试更新文档时Firestore(0.6.6-dev)中的内部错误

时间:2017-10-10 21:41:36

标签: android google-cloud-firestore

以下错误让我很难过。我正在尝试更新存储在Firestore项目中的文档中的单个字段。

    E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
  at com.google.android.gms.internal.zzejs.run(Unknown Source)
  at android.os.Handler.handleCallback(Handler.java:725)
  at android.os.Handler.dispatchMessage(Handler.java:92)
  at android.os.Looper.loop(Looper.java:176)
  at android.app.ActivityThread.main(ActivityThread.java:5365)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:511)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
  at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.IllegalStateException: Cannot perform this operation because there is no current transaction.
  at android.database.sqlite.SQLiteSession.throwIfNoTransaction(SQLiteSession.java:926)
  at android.database.sqlite.SQLiteSession.endTransaction(SQLiteSession.java:398)
  at android.database.sqlite.SQLiteDatabase.endTransaction(SQLiteDatabase.java:524)
  at com.google.android.gms.internal.zzefi.zzb(Unknown Source)
  at com.google.android.gms.internal.zzedu.zzcao(Unknown Source)
  at com.google.android.gms.internal.zzedu.start(Unknown Source)
  at com.google.android.gms.internal.zzeca.zza(Unknown Source)
  at com.google.android.gms.internal.zzecc.run(Unknown Source)
  at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:390)
  at java.util.concurrent.FutureTask.run(FutureTask.java:234)
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:153)
  at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:267)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
  at com.google.android.gms.internal.zzejp$zza.run(Unknown Source)
  at java.lang.Thread.run(Thread.java:856)

这是我的代码:

FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();

if(user == null){
    Log.e(LOGTAG, "Could not upload because user is not logged in.");
    return;
}

FirebaseFirestore db = FirebaseFirestore.getInstance();
DocumentReference userRef = db.collection("users").document(user.getUid());

TextInputEditText textview = findViewById(R.id.edit_text_foo);
String enteredText = textview.getText().toString(); //implements CharSequence, thus toString() gives the correct string
userRef.update("field_foo", enteredText)
        .addOnSuccessListener(new OnSuccessListener<Void>() {
            @Override
            public void onSuccess(Void aVoid) {
                Log.i(LOGTAG, "Text successfully updated!");
            }
        })
        .addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Log.w(TAG, "Error updating text", e);
            }
        });

每次执行方法时都会发生错误。 Imho,“内部错误”短语可能表明这确实是Firestore数据库早期beta状态的问题。然而,这是我的第一个Android应用程序,我也是Firebase的新手,所以任何合格的估值,任何解决方案的想法或任何指向愚蠢的newbe错误的指针都是受欢迎的。

提前致谢, DAND

2 个答案:

答案 0 :(得分:6)

感谢@hatboysam,它现在有效。 解决方案尽可能简单:

清除设备上应用程序管理器中的数据。

然后再次运行该应用程序。

答案 1 :(得分:0)

在许多进程中多次初始化Firestore对象时会发生此问题。因此,不是一次又一次地声明它,而是全局声明它并相应地使用..