我正在使用SetValueAsync()并传递HashMap来更新数据库,代码在一台笔记本电脑上运行正常,但是当我尝试在另一台笔记本电脑上运行相同的代码时。尽管它没有给出任何错误,但是没有更新数据库。
这是初始化应用的代码
FileInputStream serviceAccount =
new FileInputStream("src/Files/serviceAccountKey.json");
FirebaseOptions options = new FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl("https://news-article-summarizer.firebaseio.com")
.build();
FirebaseApp.initializeApp(options);
//final FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("database");
ref.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
Object document = dataSnapshot.getValue();
System.out.println(document);
}
@Override
public void onCancelled(DatabaseError error) {
}
});
这是我要更新数据库的功能
private static void SaveData(int newsSite,Map<String, Article> dataMap,DatabaseReference ref) {
switch(newsSite)
{
case 1:
ref.child("PakObserver").setValueAsync(dataMap);
break;
case 2:
ref.child("DawnNews").setValueAsync(dataMap);
break;
case 3:
ref.child("TheNation").setValueAsync(dataMap);
break;
case 4:
ref.child("TribuneNews").setValueAsync(dataMap);
break;
case 5:
ref.child("DailyTime").setValueAsync(dataMap);
break;
}