尝试更新文档时 Firestore (0.6.6-dev) 出现内部错误
Internal error in Firestore (0.6.6-dev) when trying to update document
下面的错误让我很为难。我正在尝试更新存储在我的 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.access1(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);
}
});
每次执行该方法都会出错。恕我直言,“内部错误”短语可能表明这确实是 Firestore 数据库的早期测试状态带来的问题。但是,这是我的第一个 android 应用程序,我也是 Firebase 的新手。任何合格的估值,任何解决方案的想法或任何指示?
感谢@hatboysam,现在可以使用了。
解决方案尽可能简单:
清除设备上应用程序管理器中的数据。
然后 运行 再次应用。
当您在多个进程中多次初始化 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.access1(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);
}
});
每次执行该方法都会出错。恕我直言,“内部错误”短语可能表明这确实是 Firestore 数据库的早期测试状态带来的问题。但是,这是我的第一个 android 应用程序,我也是 Firebase 的新手。任何合格的估值,任何解决方案的想法或任何指示?
感谢@hatboysam,现在可以使用了。 解决方案尽可能简单:
清除设备上应用程序管理器中的数据。
然后 运行 再次应用。
当您在多个进程中多次初始化 Firestore 对象时会出现此问题。因此,不要一次又一次地声明它,而是全局声明并相应地使用..