0
我有兩個活動,第一個是註冊活動,第二個是我想向第一個活動添加一些數據到同一個數據庫。 錯誤,當我點擊在RegisterInformationActivity BTN這是我得到的是: 「無法保存parseuser,直到它已簽署了」將數據添加到Parse.com Android
第一項活動:
public class RegisterActivity extends Activity {
ImageButton signup;
EditText username;
EditText password;
EditText email;
EditText confirmpassword;
String usernametxt;
String emailtxt;
String passwordtxt;
String confirmpasswordtxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_singup);
username = (EditText)findViewById(R.id.editTextFirstNameSingup);
password = (EditText)findViewById(R.id.editTextPasswordSingup);
email = (EditText)findViewById(R.id.editTextEmailSingup);
confirmpassword = (EditText)findViewById(R.id.editTextPasswordConfirmSingup);
signup = (ImageButton) findViewById(R.id.imageButtonSignUpWithEmail);
signup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
usernametxt = username.getText().toString();
emailtxt = email.getText().toString();
passwordtxt = password.getText().toString();
confirmpasswordtxt = confirmpassword.getText().toString();
if(usernametxt.equals("") && passwordtxt.equals("") && emailtxt.equals("") && confirmpasswordtxt.equals("")) {
Toast.makeText(getApplicationContext(), "Please complete the sign up form", Toast.LENGTH_LONG).show();
}else if(!confirmpasswordtxt.equals(passwordtxt)) {
Toast.makeText(getApplicationContext(), "Passwords doesn't match", Toast.LENGTH_LONG).show();
}else{
// Save new user data into Parse.com storage data (VALJDA!)
ParseUser user = new ParseUser();
user.setUsername(usernametxt);
user.setPassword(passwordtxt);
user.setEmail(emailtxt);
user.signUpInBackground(new SignUpCallback() {
@Override
public void done(ParseException e) {
if(e == null){
// Toast for succefull registration
Intent intent = new Intent(RegisterActivity.this, RegisterInformationActivity.class);
startActivity(intent);
finish();
Toast.makeText(getApplicationContext(), "Successfully Signed up, please log in.", Toast.LENGTH_LONG).show();
}else{
Toast.makeText(getApplicationContext(), "Sign up Error", Toast.LENGTH_LONG).show();
}
}
});
}
}
});
}}
次活動,RegisterInfromationActivity:
public class RegisterInformationActivity extends Activity {
ImageButton btn;
EditText cigsInADay;
EditText boxWorth;
EditText cigsInABox;
EditText howLong;
String cigsInADayTxt;
String boxWorthTxt;
String cigsInABoxTxt;
String howLongTxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_registerinformation);
cigsInABox = (EditText)findViewById(R.id.editTextCigginabox);
boxWorth = (EditText)findViewById(R.id.editTextBoxworth);
cigsInADay = (EditText)findViewById(R.id.editTextCigarettes);
howLong = (EditText)findViewById(R.id.editTextHowlong);
btn = (ImageButton)findViewById(R.id.imageButtonToWelcomeScreen);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
cigsInABoxTxt = cigsInABox.getText().toString();
boxWorthTxt = boxWorth.getText().toString();
cigsInADayTxt = cigsInADay.getText().toString();
howLongTxt = howLong.getText().toString();
if(cigsInABoxTxt.equals("") && boxWorthTxt.equals("") && cigsInADayTxt.equals("") && howLongTxt.equals("")){
Toast.makeText(getApplicationContext(),"Please complete all forms",Toast.LENGTH_LONG).show();
}else{
if(ParseAnonymousUtils.isLinked(ParseUser.getCurrentUser())) {
// If user is anonymous, it will stay in this activity
Toast.makeText(getApplicationContext(), "Please sign up or login", Toast.LENGTH_LONG).show();
}else{
// If the current user is NOT anonymous
// Get current user data from PARSE.com
ParseUser currentUser = ParseUser.getCurrentUser();
if (currentUser != null) {
//Send loged in user to MainActivity.class
// Send user to Welcome.class
ParseObject object = ParseObject.create(" User");
object.put("cenakutije", boxWorthTxt);
object.put("kolicinakutije", cigsInABoxTxt);
object.put("cigaretanadan", cigsInADayTxt);
object.put("duzinapusenja", howLongTxt);
object.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if(e == null) {
setResult(RESULT_OK);
finish();
}else{
Toast.makeText(getApplicationContext(),"Error: " + e.getMessage(),Toast.LENGTH_LONG).show();
}
}
});
}else{
Toast.makeText(getApplicationContext(),"ono trece",Toast.LENGTH_LONG).show();
}
}
}
ParseObject object = ParseObject.create("_User");
object.put("cenakutije", boxWorthTxt);
object.put("kolicinakutije", cigsInABoxTxt);
object.put("cigaretanadan", cigsInADayTxt);
object.put("duzinapusenja", howLongTxt);
object.saveInBackground(new SaveCallback() {
@Override
public void done(ParseException e) {
if(e == null) {
setResult(RESULT_OK);
finish();
}else{
Toast.makeText(getApplicationContext(),"Error: " + e.getMessage(),Toast.LENGTH_LONG).show();
}
}
});
}});}
}
這樣做對您有幫助嗎? – Urban
對不起,遲到的答案。我很忙。 我無法調用logInInBackground()。 –
爲什麼不能調用loginInBackground? – Urban