我是一名Android学生,我正在尝试设置一个注册屏幕并将用户保存在parse.com中,但是当我点击注册按钮时出现错误,我就不会这样做。我知道为什么。此外,我不知道如何测试密码和重复密码可编辑文本是否相同。
public void onCreate (Bundle saveInstanceState) {
super.onCreate(saveInstanceState);
setContentView(R.layout.signupscreen);
Button signup = (Button) findViewById(R.id.signup);
signup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String username = String.valueOf(findViewById(R.id.username_edittext));
String password = String.valueOf(findViewById(R.id.password_edittext));
String repassword = String.valueOf(findViewById(R.id.repassword_edittext));
String email = String.valueOf(findViewById(R.id.email_edittext));
String universitat = String.valueOf(findViewById(R.id.universitat_edittext));
String carrera = String.valueOf(findViewById(R.id.carrera_edittext));
// Force user to fill up the form
if (username.equals("") && password.equals("")) {
Toast.makeText(getApplicationContext(),
"Please complete the sign up form",
Toast.LENGTH_LONG).show();
} else {
// Save new user data into Parse.com Data Storage
ParseUser user = new ParseUser();
user.setUsername(username);
user.setPassword(password);
user.setEmail(email);
// Introduir universitat i carrera d'una llista de la DB sincronitzada amb Parse
//user.put("carrera", carrera);
//user.put("universitat", universitat);
Log.v("username: ", username);
Log.v("password: ", password);
Log.v("email: ", email);
user.signUpInBackground(new SignUpCallback() {
@Override
public void done(com.parse.ParseException e) {
if (e == null) {
// Show a simple Toast message upon successful registration
Toast.makeText(getApplicationContext(),
"Successfully Signed up, please log in.",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(),
"Sign up Error", Toast.LENGTH_LONG)
.show();
}
}
});
}
}
});
}
错误讯息:
06-09 22:23:52.764 5833-6759/com.example.aleix.selenotesapp D/libc﹕ [NET] android_getaddrinfofornet+,hn 13(0x6170692e706172),sn(),hints(known),family 0,flags 4
06-09 22:23:52.764 5833-6759/com.example.aleix.selenotesapp D/libc﹕ [NET] android_getaddrinfofornet-, err=8
06-09 22:23:52.764 5833-6759/com.example.aleix.selenotesapp D/libc﹕ [NET] android_getaddrinfofornet+,hn 13(0x6170692e706172),sn(),hints(known),family 0,flags 1024
06-09 22:23:52.764 5833-6759/com.example.aleix.selenotesapp D/libc﹕ [NET] android_getaddrinfofornet-, pass to proxy
06-09 22:23:52.774 5833-6759/com.example.aleix.selenotesapp D/libc﹕ [NET] android_getaddrinfo_proxy+
06-09 22:23:52.774 5833-6759/com.example.aleix.selenotesapp D/libc﹕ [NET] android_getaddrinfo_proxy get netid:0
06-09 22:23:52.814 5833-6759/com.example.aleix.selenotesapp D/libc﹕ [NET] android_getaddrinfo_proxy-, success
06-09 22:23:52.824 5833-6759/com.example.aleix.selenotesapp D/libc﹕ [NET] android_getaddrinfofornet+,hn 13(0x35342e38382e31),sn(),hints(known),family 0,flags 4
06-09 22:23:52.824 5833-6759/com.example.aleix.selenotesapp D/libc﹕ [NET] android_getaddrinfofornet-, SUCCESS
06-09 22:23:53.324 5833-6759/com.example.aleix.selenotesapp D/libc﹕ [NET] android_getaddrinfofornet+,hn 13(0x6170692e706172),sn(),hints(known),family 0,flags 4
06-09 22:23:53.324 5833-6759/com.example.aleix.selenotesapp D/libc﹕ [NET] android_getaddrinfofornet-, err=8
答案 0 :(得分:0)
正如我上面提到的,通常你会使用像
这样的东西findViewById(R.id.username_edittext).getText().toString()
获取EditText
的值。