从Firebase

时间:2018-04-20 10:30:06

标签: android firebase firebase-realtime-database

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_in);

    editPassword = (MaterialEditText) findViewById(R.id.editPassword);
    editPhone = (MaterialEditText) findViewById(R.id.editPhone);
    btnSignIn = findViewById(R.id.btnSignIn);

    FirebaseDatabase database = FirebaseDatabase.getInstance();
    final DatabaseReference table_user = database.getReference("User");

    btnSignIn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            final ProgressDialog mDialog = new ProgressDialog(SignIn.this);
            mDialog.setMessage("please waiting...");
            mDialog.show();

            table_user.addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {

                    if (dataSnapshot.child(editPhone.getText().toString()).exists()) {
                        mDialog.dismiss();


                        User user = dataSnapshot.child(editPhone.getText().toString()).getValue(User.class);
                        if ((user.getPassword().toString()).equals(editPassword.getText().toString())) {
                            Toast.makeText(SignIn.this, "sign in successfully !", Toast.LENGTH_SHORT).show();
                        } else {
                            Toast.makeText(SignIn.this, "sign in failed !!!", Toast.LENGTH_SHORT).show();
                        }
                    } else {
                        Toast.makeText(SignIn.this, "user not exist", Toast.LENGTH_SHORT).show();
                    }
                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });
        }
    });
}

此处User是一个以String类型存储移动号码,名称和密码数据的类 在检查用户是否存在后,我的应用程序正在“遗憾地停止”错误。

 User user = dataSnapshot.child(editPhone.getText().toString()).getValue(User.class);

我认为错误就在这一行。

错误消息是:

Note: C:\Users\Tejas\AndroidStudioProjects\Foody\app\src\main\java\com\bhadresha\tejas\foody\SignIn.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

0 个答案:

没有答案