【发布时间】:2021-12-31 00:59:25
【问题描述】:
我不知道为什么 dataSnapshot 不起作用。
符号:可变数据快照
private void Startplaylist(String mood) {
DatabaseReference p_ref = FirebaseDatabase.getInstance().getReference("Playlist");
//DatabaseReference p_music = (DatabaseReference) p_ref.child("Playlist_Mood").equalTo(mood);
p_ref.child("Playlist_ID").equalTo(0).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
music_id = dataSnapshot.getValue("Playlist_Id"); // Problem HERE!!
str_musictitle.setText(music_id);
//music_id = snapshot.getValue(String.class);
//str_musictitle.setText(music_id);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}
这是我的 build.gradle(Module: app) 代码。
dependencies {
/-- fire storage--/
implementation 'com.github.bumptech.glide:glide:4.11.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
implementation platform('com.google.firebase:firebase-bom:28.4.1')
implementation 'com.google.firebase:firebase-analytics'
implementation 'com.google.firebase:firebase-database:19.2.0'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.firebase:firebase-database:19.2.1'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
我苦苦搜索,寻找解决方案,但我无法解决,所以我问了一个问题。
【问题讨论】:
-
我投票结束这个问题,因为请不要使用代码截图,使用 WYSIWYG 格式化它
-
不应该只是快照吗?
-
只是一个简单的错字。 var 定义为
snapshot此处为(@NonNull DataSnapshot snapshot),之后您将使用snapShot此处为music_id = dataSnapshot。由于打字错误而关闭
标签: java android firebase firebase-realtime-database google-cloud-platform