Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/379.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
Java 我如何获得要显示的数据?我的Firebase实时数据库仍然显示为空_Java_Android_Firebase_Firebase Realtime Database - Fatal编程技术网

Java 我如何获得要显示的数据?我的Firebase实时数据库仍然显示为空

Java 我如何获得要显示的数据?我的Firebase实时数据库仍然显示为空,java,android,firebase,firebase-realtime-database,Java,Android,Firebase,Firebase Realtime Database,我正在尝试将我的实时Firebase数据库与我的代码同步。 我目前正在使用Firebase Auth,并且我能够获得用户ID,但我的实时数据库保持为空。我的Firebase实时数据库规则当前设置为true。 我的代码有问题吗?我正在尝试将用户id、名字和姓氏拉入Firebase数据库 public class Add_Info_After_Registration extends AppCompatActivity { private EditText FirstName, LastNa

我正在尝试将我的实时Firebase数据库与我的代码同步。 我目前正在使用Firebase Auth,并且我能够获得用户ID,但我的实时数据库保持为空。我的Firebase实时数据库规则当前设置为true。 我的代码有问题吗?我正在尝试将用户id、名字和姓氏拉入Firebase数据库

public class Add_Info_After_Registration extends AppCompatActivity {
    private EditText FirstName, LastName;
    private ImageButton RegisterInfoButton;
    private FirebaseAuth mAuth;
    private DatabaseReference UsersReference;

    //Firebase Things//
    String currentUserID;
    //Firebase Things//

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_add__info__after__registration);

        //this is referring to storing username information in firebase//
        mAuth = FirebaseAuth.getInstance();
        currentUserID = mAuth.getCurrentUser().getUid();
        UsersReference = FirebaseDatabase.getInstance().getReference().child("Users").child(currentUserID);
        //this is referring to storing username information in firebase//

        FirstName = (EditText) findViewById(R.id.add_info_first_name);
        LastName = (EditText) findViewById(R.id.add_info_last_name);
        RegisterInfoButton = (ImageButton) findViewById(R.id.register_submit_button);
        mAuth = FirebaseAuth.getInstance();

        RegisterInfoButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v)
            {
                SaveAccountSetUpInformation();
                SendUserToMainActivity();
            }
        });
    }

    private void SaveAccountSetUpInformation()
    {
        String firstname = FirstName.getText().toString();
        String lastname = LastName.getText().toString();

        if(TextUtils.isEmpty(firstname))
        {
            Toast.makeText(this, "Please insert first name", Toast.LENGTH_SHORT).show();
        }

        if(TextUtils.isEmpty(lastname))
        {
            Toast.makeText(this, "Please insert last name", Toast.LENGTH_SHORT).show();
        }
        else
        {
            HashMap userMap = new HashMap();
            userMap.put("firstname", firstname);
            userMap.put("lastname", lastname);
            //this is referring to storing username information in firebase//    
            UsersReference.updateChildren(userMap).addOnCompleteListener(new OnCompleteListener() {
                @Override
                public void onComplete(@NonNull Task task)
                {
                    if(task.isSuccessful())
                    {
                        SendUserToMainActivity();
                        Toast.makeText(Add_Info_After_Registration.this, "Your Account is Created Sucessfully", Toast.LENGTH_LONG).show();
                    }
                    else
                    {
                        String message = task.getException().getMessage();
                        Toast.makeText(Add_Info_After_Registration.this, "Error Occured:"+ message, Toast.LENGTH_SHORT).show();
                    }
                }
            });
        }
    }

    private void SendUserToMainActivity()
    {
        Intent setupIntent = new Intent(Add_Info_After_Registration.this, MainActivity.class);
        setupIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(setupIntent);
        finish();
    }
}

您是否已经在
onComplete
中设置了断点?它被击中了吗?如果你采用这种方法会发生什么?
firstname
lastname
的值是多少?是否显示“您的帐户创建成功”?是。我的帐户已成功创建。当他们登录时,我会得到用户ID。更新:这个问题现在已经解决了。我注意到我的JDK没有更新。数据现在正在吸收。谢谢大家的帮助。:)