Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/310.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Firebase管理sdk与java不兼容';t连接_Java_Database_Firebase_Firebase Realtime Database_Google Admin Sdk - Fatal编程技术网

Firebase管理sdk与java不兼容';t连接

Firebase管理sdk与java不兼容';t连接,java,database,firebase,firebase-realtime-database,google-admin-sdk,Java,Database,Firebase,Firebase Realtime Database,Google Admin Sdk,我正在尝试使用firebase数据库创建一个java桌面RMI数据管理系统。我的第一步是使用AdminSDK确认firebase的连接。我完全按照指南中的步骤进行,没有取得任何进展。程序会执行,但firebase控制台中没有数据修改 以下是我目前掌握的代码 public class Main{ public static class User2 { public String date_of_birth; public String full_name

我正在尝试使用firebase数据库创建一个java桌面RMI数据管理系统。我的第一步是使用AdminSDK确认firebase的连接。我完全按照指南中的步骤进行,没有取得任何进展。程序会执行,但firebase控制台中没有数据修改

以下是我目前掌握的代码

public class Main{

    public static class User2 {

        public String date_of_birth;
        public String full_name;
        public String nickname;

        public User2(String dateOfBirth, String fullName) {
            this.date_of_birth = dateOfBirth;
            this.full_name = fullName;
        }

        public User2(String dateOfBirth, String fullName, String nickname) {
            this.date_of_birth = dateOfBirth;
            this.full_name = fullName;
            this.nickname = nickname;
        }
    }

    public static void main(String[] args) {

        FileInputStream serviceAccount = null;
        try {

            serviceAccount = new FileInputStream("rathnapuralabs-firebase-adminsdk-okzic-f6313557b4.json");
        } catch (FileNotFoundException e) {

            e.printStackTrace();
        }

        FirebaseOptions options = null;
        try {

            options = new FirebaseOptions.Builder()
                    .setCredentials(GoogleCredentials.fromStream(serviceAccount))
                    .setDatabaseUrl("https://rathnapuralabs.firebaseio.com")
                    .build();
        } catch (IOException e) {

            e.printStackTrace();
        }
        FirebaseApp.initializeApp(options);

        DatabaseReference ref = FirebaseDatabase.getInstance()
                .getReference();

        DatabaseReference usersRef = ref.child("users2");

        Map<String, User2> users = new HashMap<>();
        users.put("alanisawesome", new User2("June 23, 1912", "Alan Turing"));
        users.put("gracehop", new User2("December 9, 1906", "Grace Hopper"));

        usersRef.setValueAsync(users);

        ref.addListenerForSingleValueEvent(new ValueEventListener() {
           @Override
           public void onDataChange(DataSnapshot dataSnapshot) {
               Object document = dataSnapshot.getValue();
               System.out.println(document);
           }

           @Override
           public void onCancelled(DatabaseError error) {
           }
    });
    }
公共类主{
公共静态类User2{
公共字符串出生日期;
公共字符串全名;
公共字符串昵称;
公共用户2(字符串dateOfBirth,字符串fullName){
this.date\u of\u birth=出生日期;
this.full_name=全名;
}
公共用户2(字符串dateOfBirth、字符串全名、字符串昵称){
this.date\u of\u birth=出生日期;
this.full_name=全名;
this.昵称=昵称;
}
}
公共静态void main(字符串[]args){
FileInputStream serviceAccount=null;
试一试{
serviceAccount=新文件输入流(“rathnapuralabs-firebase-adminsdk-okzic-f6313557b4.json”);
}catch(filenotfounde异常){
e、 printStackTrace();
}
FirebaseOptions=null;
试一试{
选项=新的FirebaseOptions.Builder()
.setCredentials(GoogleCredentials.fromStream(serviceAccount))
.setDatabaseUrl(“https://rathnapuralabs.firebaseio.com")
.build();
}捕获(IOE异常){
e、 printStackTrace();
}
FirebaseApp.initializeApp(选项);
DatabaseReference ref=FirebaseDatabase.getInstance()
.getReference();
DatabaseReference usersRef=ref.child(“users2”);
Map users=newhashmap();
users.put(“alanisawesome”,新用户2(“1912年6月23日”,“Alan Turing”));
用户。put(“gracehop”,新用户2(“1906年12月9日”,“GraceHopper”);
usersRef.setValueAsync(用户);
ref.addListenerForSingleValueEvent(新的ValueEventListener(){
@凌驾
公共void onDataChange(DataSnapshot DataSnapshot){
对象文档=dataSnapshot.getValue();
系统输出打印项次(文件);
}
@凌驾
已取消的公共无效(DatabaseError错误){
}
});
}
这段代码给了我三行错误

SLF4J:未能加载类“org.SLF4J.impl.StaticLoggerBinder”

SLF4J:默认为无操作(NOP)记录器实现

SLF4J:有关更多详细信息,请参阅

但有些事情告诉我,即使有这些错误,数据仍然应该保存到firebase

下面是代码和关键json的github链接


以下代码适用于我:

try {
            FirebaseOptions options = new FirebaseOptions.Builder()
                    .setCredentials(GoogleCredentials
                                    .fromStream(new ClassPathResource("/firebase-authentication.json").getInputStream()))
                    .build();

            if (FirebaseApp.getApps().isEmpty()) {
                FirebaseApp.initializeApp(options);
            }

        } catch (IOException e) {
            e.printStackTrace();
        }

“/firebase authentication.json”在resources文件夹中。

错误是由于sl4j logger的配置不正确造成的,您可以暂时忽略它,因为它与实际数据无关operation@Kushan我也这么认为。谢谢。我试过了,但仍然不起作用。这些代码非常相似。所以我认为它们都应该起作用。我的代码也是来自firebase指南。可以吗请您亲自查看github的项目,如果您不介意的话,也许您可以向我展示您的项目。我使用我的项目只是为了测试Firebase Auth。不知道它是否对您有用。但您使用自己的Firebase身份验证文件,对吗?您说的是json文件。是的,我知道您的pom.xml文件丢失了在github上。你能提供它吗?我没有这样的文件。我需要创建它吗