Firebaseにアカウントを作成しました。プロジェクト名は "Fieldglass"で作成しました。値がFirebaseデータベースに挿入されていません
は今firebaseアカウントでデータベース]タブをクリック上の私は名前のデータベースを取得する:fieldglass-aeca7
今私は、この内部値を挿入します。私はOnCreate()
関数でコードを書いています。
final CountDownLatch sync = new CountDownLatch(1);
DatabaseReference db= FirebaseDatabase.getInstance().getReference("fieldglass-aeca7");
String userId=db.push().getKey();
User u=new User("shikher","[email protected]");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
db.child(userId).setValue(u).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(Task<Void> task) {
sync.countDown();
}
});
try{
sync.await();
}
catch (Exception e)
{
System.out.print("there is an exception here in sync.await()");
}
このコードを実行した後、値はコンソールでデータベースに挿入されません。 Firebaseのデータベースに値を挿入するにはどうしたらいいですか?
ユーザークラスは次のとおりです。
package com.example.hsports.galleryusingimageswitcher; /**
* Created by I324671 on 11/7/2016.
*/
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class User {
public String name;
public String email;
public User(){
}
public User(String name,String email)
{
this.name=name;
this.email=email;
}
}
あなたはアプリケーションがデータベースへの書き込みを許可されていることを確かめていますか?不明な場合は、データベースのルールを投稿してください。 – Wilik
{ "ルール":{ ".read ":真、 " .WRITE":真 } は}これらは私がfirebase –
HMにおけるルール]タブの下に指定している私のデータベースルールです。あなたは 'User'クラスを投稿できますか? – Wilik