无法从我的Android应用程序写入Firebase数据库

时间:2018-03-12 09:25:48

标签: android firebase firebase-realtime-database

这是我用来连接和写入数据库的代码(我想创建一个新的子节点userand并为其赋值alex。

DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();
mDatabase.child("user").setValue("alex");

注意:我已遵循正确的设置说明并将读取和写入的授权更改为true。代码工作了大约一个月,但现在我无法弄清楚为什么它没有写入数据库。

下面是我的logcat

03-12 14:43:38.882 12158-12158/? I/art: Late-enabling -Xcheck:jni
03-12 14:43:38.900 12158-12165/? I/art: Debugger is no longer active
03-12 14:43:38.900 12158-12165/? I/art: Starting a blocking GC Instrumentation
03-12 14:43:38.923 12158-12158/? W/System: ClassLoader referenced unknown path: /data/app/anaysingh.anaytyproject-1/lib/arm
03-12 14:43:38.932 12158-12158/? I/InstantRun: Instant Run Runtime started. Android package is anaysingh.anaytyproject, real application class is null.
03-12 14:43:39.090 12158-12158/? W/System: ClassLoader referenced unknown path: /data/app/anaysingh.anaytyproject-1/lib/arm
03-12 14:43:39.127 12158-12158/? D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
03-12 14:43:39.136 12158-12158/? D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.
03-12 14:43:39.247 12158-12158/? V/FA: Cancelling job. JobID: -129726599
03-12 14:43:39.253 12158-12158/? V/FA: Registered activity lifecycle callback
03-12 14:43:39.255 12158-12158/? I/FirebaseInitProvider: FirebaseApp initialization successful
03-12 14:43:39.264 12158-12174/? V/FA: Collection enabled
03-12 14:43:39.264 12158-12174/? V/FA: App package, google app id: anaysingh.anaytyproject, 1:1025179625916:android:afeaaa816280de9a
03-12 14:43:39.266 12158-12174/? I/FA: App measurement is starting up, version: 11910
03-12 14:43:39.266 12158-12174/? I/FA: To enable debug logging run: adb shell setprop log.tag.FA VERBOSE
03-12 14:43:39.266 12158-12174/? I/FA: To enable faster debug mode event logging run:
                                         adb shell setprop debug.firebase.analytics.app anaysingh.anaytyproject
03-12 14:43:39.266 12158-12174/? D/FA: Debug-level message logging enabled
03-12 14:43:39.278 12158-12174/? V/FA: Connecting to remote service
03-12 14:43:39.293 12158-12174/? V/FA: Connection attempt already in progress
03-12 14:43:39.379 12158-12158/? W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
03-12 14:43:39.384 12158-12158/? V/FA: onActivityCreated
03-12 14:43:39.534 12158-12158/? D/Connection: https://anaytyproject.firebaseio.com/Nigga
03-12 14:43:39.551 12158-12174/? V/FA: Connection attempt already in progress
03-12 14:43:39.556 12158-12174/? I/FA: Tag Manager is not found and thus will not be used
03-12 14:43:39.557 12158-12174/? D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-4541290412013862895}]
03-12 14:43:39.559 12158-12177/? I/DynamiteModule: Considering local module com.google.android.gms.firebase_database:4 and remote module com.google.android.gms.firebase_database:6
03-12 14:43:39.559 12158-12177/? I/DynamiteModule: Selected remote version of com.google.android.gms.firebase_database, version >= 6
03-12 14:43:39.566 12158-12177/? W/System: ClassLoader referenced unknown path: 
03-12 14:43:39.573 12158-12174/? V/FA: Connection attempt already in progress
03-12 14:43:39.574 12158-12174/? V/FA: Activity resumed, time: 4225355
03-12 14:43:39.582 12158-12177/? W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/0000004c/n/armeabi-v7a
03-12 14:43:39.582 12158-12177/? W/System: ClassLoader referenced unknown path: /data/user_de/0/com.google.android.gms/app_chimera/m/0000004c/n/armeabi
03-12 14:43:39.604 12158-12178/? I/Adreno: QUALCOMM build                   : bc479b6, I15255e4b4a
                                           Build Date                       : 02/22/17
                                           OpenGL ES Shader Compiler Version: XE031.09.00.03
                                           Local Branch                     : 
                                           Remote Branch                    : refs/tags/AU_LINUX_ANDROID_LA.UM.5.5.R1.07.00.00.269.019
                                           Remote Branch                    : NONE
                                           Reconstruct Branch               : NOTHING
03-12 14:43:39.608 12158-12178/? I/OpenGLRenderer: Initialized EGL, version 1.4
03-12 14:43:39.608 12158-12178/? D/OpenGLRenderer: Swap behavior 1
03-12 14:43:39.625 12158-12179/? D/NetworkSecurityConfig: No Network Security Config specified, using platform default
03-12 14:43:39.659 12158-12174/? D/FA: Connected to remote service
03-12 14:43:39.660 12158-12174/? V/FA: Processing queued up service tasks: 4
03-12 14:43:44.701 12158-12174/anaysingh.anaytyproject V/FA: Inactivity, disconnecting from the service
03-12 14:43:56.840 12158-12174/anaysingh.anaytyproject V/FA: Recording user engagement, ms: 17290
03-12 14:43:56.840 12158-12174/anaysingh.anaytyproject V/FA: Connecting to remote service
03-12 14:43:56.842 12158-12174/anaysingh.anaytyproject V/FA: Activity paused, time: 4242644
03-12 14:43:56.844 12158-12174/anaysingh.anaytyproject D/FA: Logging event (FE): user_engagement(_e), Bundle[{firebase_event_origin(_o)=auto, engagement_time_msec(_et)=17290, firebase_screen_class(_sc)=MainActivity, firebase_screen_id(_si)=-4541290412013862895}]
03-12 14:43:56.852 12158-12174/anaysingh.anaytyproject V/FA: Connection attempt already in progress
03-12 14:43:56.852 12158-12174/anaysingh.anaytyproject D/FA: Connected to remote service
03-12 14:43:56.852 12158-12174/anaysingh.anaytyproject V/FA: Processing queued up service tasks: 2

我做错了什么,我的firebase数据库仍显示为null。但是,当我手动添加数据并通过JS读取时,它正常工作。

1 个答案:

答案 0 :(得分:0)

错误告诉您,您尚未将Firebase链接到您的项目。

03-12 14:43:39.127 12158-12158/? D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization.
03-12 14:43:39.136 12158-12158/? D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not linked. Skipping initialization.

使用Firebase智能助理进行设置:

To open the Firebase Assistant in Android Studio:

Click Tools > Firebase to open the Assistant window.
Click to expand one of the listed features (for example, Analytics), then click the provided tutorial link (for example, Log an Analytics event).
Click the Connect to Firebase button to connect to Firebase and add the necessary code to your app.

完整文档here