Androidスタジオアプリでレジスターアクト(Java)を作成しており、性別のラジオグループがあります。ラジオボタンをクリックして性別を選択すると、アプリがクラッシュするという問題があります。私のコードが情報を取得して解析に保存するのに適しているかどうか、または解析に保存しようとしている方法が問題であるかどうかはわかりません
enter code here
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
import com.parse.ParseException;
import com.parse.ParseUser;
import com.parse.SignUpCallback;
public class RegisterActivity extends AppCompatActivity {
protected EditText mUserFirstname;
protected EditText mUserLastname;
protected EditText mUsername;
protected EditText mUserPassword;
protected EditText mUserEmail;
protected EditText mUserPhonenumber;
protected EditText mUserPostalcode;
protected RadioGroup mGender;
protected RadioButton mMale;
protected RadioButton mFemale;
protected EditText mDob;
protected Button mRegisterbutton;
private static final String COLUMN_GENDER = ""; //put here name of your column from table on Parse.com
private static final String MALE = ""; //put here value for male. Check the type of gender column on Parse.com (String, Number (Integer), Boolean, etc.)
private static final String FEMALE = ""; //put here value for female. Check the type of gender column on Parse.com (String, Number (Integer), Boolean, etc.)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
mMale.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {ParseUser user = new ParseUser();
user.put(COLUMN_GENDER, MALE);
user.saveInBackground(); // if you want to save immediately
}
}
});
mFemale.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {ParseUser user = new ParseUser();
user.put(COLUMN_GENDER, FEMALE);
user.saveInBackground(); // if you want to save immediately
}
}
});
//initialize
mUserFirstname = (EditText) findViewById(R.id.firstNameRegisterEditText);
mUserLastname = (EditText) findViewById(R.id.lastNameRegisterEditText);
mUsername = (EditText) findViewById(R.id.userNameRegisterEditText);
mUserPassword = (EditText) findViewById(R.id.passwordRegisterEditText);
mUserEmail = (EditText) findViewById(R.id.emailRegisterEditText);
mUserPhonenumber = (EditText) findViewById(R.id.phoneNumberRegisterEditText);
mUserPostalcode = (EditText) findViewById(R.id.postalCodeRegisterEditText);
mGender = (RadioGroup) findViewById(R.id.radioGroup);
mMale = (RadioButton) findViewById(R.id.maleGenderRegisterEditText);
mFemale = (RadioButton) findViewById(R.id.femaleGenderRegisterEditText);
mDob = (EditText) findViewById(R.id.dateofBirthEditText);
mRegisterbutton = (Button) findViewById(R.id.registerButton);
//Listen to Register button click
mRegisterbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//toast
//get the username, password and email and convert to string
String username = mUsername.getText().toString().trim();
String password = mUserPassword.getText().toString().trim();
String email = mUserEmail.getText().toString().trim();
String firstname = mUserFirstname.getText().toString().trim();
String lastname = mUserLastname.getText().toString().trim();
String phonenumber = mUserPhonenumber.getText().toString().trim();
String postalcode = mUserPostalcode.getText().toString().trim();
String gender = mMale.isChecked() ? MALE : FEMALE;
//store user
ParseUser user = new ParseUser();
user.setUsername("my name");
user.setPassword("my pass");
user.setEmail("email@example.com");
// other fields can be set just like with ParseObject
user.put("first name", "my name");
user.put("last name", "my name");
user.put("postal", "65055");
user.put("gender", "male or female");
user.put("dob", "mm/dd/yyyy");
user.put("phone", "650-253-0000");
user.put(COLUMN_GENDER, gender);
user.signUpInBackground(new SignUpCallback() {
@Override
public void done(ParseException e) {
if (e==null) {
//user signed up succesfully
Toast.makeText(RegisterActivity.this,"Welcome To The Party...", Toast.LENGTH_LONG).show();
//take user to homepage
}else {
// there was and error sigingup user. advise user
}
}
});
}
});
});
}