标签云

微信群

扫码加入我们

WeChat QR Code

I want to login using username and password that is stored in Firebase realtime database. But my code does not work. I include my database picture and code. Please help me.This is database image:This is my main activity code MainActivity.javadatabaseReference=FirebaseDatabase.getInstance().getReference("Client");btn.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Query query = databaseReference.child("Client").orderByChild("username").equalTo(editTextUsername.getText().toString().trim());query.addListenerForSingleValueEvent(new ValueEventListener() {@Overridepublic void onDataChange(DataSnapshot dataSnapshot) {for (DataSnapshot user : dataSnapshot.getChildren()) {Users usersBean = user.getValue(Users.class);if (usersBean.password.equals(editTextPassword.getText().toString().trim())) {Toast.makeText(MainActivity.this, "success", Toast.LENGTH_SHORT).show();} else {Toast.makeText(MainActivity.this, "wrong", Toast.LENGTH_SHORT).show();}}}@Overridepublic void onCancelled(DatabaseError databaseError) {}});}});Here is my users java class Users.javapublic class Users {String email;String id;String password;String username;public Users() {}public Users(String email, String id, String password, String username) {this.email = email;this.id = id;this.password = password;this.username = username;}public String getEmail() {return email;}public void setEmail(String email) {this.email = email;}public String getId() {return id;}public void setId(String id) {this.id = id;}public String getPassword() {return password;}public void setPassword(String password) {this.password = password;}public String getUsername() {return username;}public void setUsername(String username) {this.username = username;}}


not working.when i clicked button app is stopped.Alex Mamo

2019年04月25日55分34秒

If the app crashes, there is a stack trace. Please look that up on logcat, and add it to your question.

2019年04月25日55分34秒

Here is logcat; drive.google.com/open?id=11kpO1jHwwnokIEuf2B1a-FZrmPPJe6bL ..Alex Mamo

2019年04月25日55分34秒

Please see my updated answer. Does it work now?

2019年04月25日55分34秒

Not work...i try adding indexOn still failed..please implement it in your IDE and run..Alex Mamo

2019年04月25日55分34秒