-2
Retriving數據我不知道什麼是錯的代碼..應用程序已停止 - 從火力
當我輸入的信息,我的應用程序顯示了 - 可惜停止。 要訪問這兩個區域,我已經在頂部聲明瞭字符串。 IDE也不顯示任何錯誤。
我也跟着從stackoverflow一些答案,但錯誤仍然是一樣的。
retrive數據和我的代碼 -
public class LoginPage extends AppCompatActivity {
FirebaseDatabase database;
DatabaseReference myRef;
String name, password, email, edtName, edtPassword;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login_page);
final EditText uname, pass;
Button login, signup;
uname = (EditText) findViewById(R.id.editUsername);
pass = (EditText) findViewById(R.id.editPassword);
login = (Button) findViewById(R.id.buttonLogin);
signup = (Button) findViewById(R.id.buttonSignup);
edtName = uname.getText().toString();
edtPassword = pass.getText().toString();
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(LoginPage.this, "Button Tapped", Toast.LENGTH_SHORT).show();
DatabaseReference zonesRef = FirebaseDatabase.getInstance().getReference("sampBase");
DatabaseReference zone1Ref = zonesRef.child(name);
DatabaseReference zone1NameRef = zone1Ref.child("Name");
DatabaseReference zone1PassRef = zone1Ref.child("Password");
// name retrive
zone1NameRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
name = dataSnapshot.getValue(String.class);
Toast.makeText(LoginPage.this, name+" is name", Toast.LENGTH_SHORT).show();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
// password retrive
zone1PassRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
password = dataSnapshot.getValue(String.class);
if(password != edtPassword){
Toast.makeText(LoginPage.this, "Wrong password.!", Toast.LENGTH_SHORT).show();
pass.setText("");
return;
}
else{
Toast.makeText(LoginPage.this, "Login Successful.!", Toast.LENGTH_SHORT).show();
Intent i = new Intent(LoginPage.this, HomePage.class);
i.putExtra("Name", name);
startActivity(i);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
});
}
}
我想'DatabaseReference zone1Ref = zonesRef.child(名);''name'是在這一點上 – Omer
打印堆棧跟蹤,請空,檢查:https://stackoverflow.com/questions/7841232/java -Android-如何對打印出一個全棧追蹤 –