こんにちは、このコードを Android アプリに追加したところ、突然動作しなくなりました (起動しません)。帰国日が出発日より前の日付が選択されている場合、ユーザーが先に進むことを許可されていないことを確認しようとしています。
String departureDateTemp = dYear+ ""+ ""+dMonth + ""+dDay;
int departureDateTemp2 = Integer.parseInt(departureDateTemp);
String returnDateTemp = rYear+ ""+ ""+rMonth + ""+rDay;
int returnDateTemp2 = Integer.parseInt(returnDateTemp);
if(returnDateTemp2 >= departureDateTemp2){
//MESSAGE
if(buttonR.isChecked()){
String returnDate = txR.getText().toString();
basket.putString("returnDate", returnDate);
type = "Return";
}
else{
type = "Oneway";
}
}
else{
btnSubmit.setEnabled(false);
}
私の完全な活動はこれです
public class MainActivity extends FragmentActivity {
private int dYear;
private int dMonth;
private int dDay;
private int rYear;
private int rMonth;
private int rDay;
static final int dDATE_DIALOG_ID = 0;
static final int rDATE_DIALOG_ID = 1;
private RadioButton buttonO = null;
private RadioButton buttonR = null;
private TableRow tr;
TextView txD, txR;
private Button btnDepart,btnReturn, btnSubmit,btnClose;
private Spinner noOfPassengersSpinner,departureSpinner,returnSpinner;
private CheckBox tandCCB;
final Context context = this;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonO = (RadioButton) findViewById(R.id.radioO);
buttonR = (RadioButton) findViewById(R.id.radioR);
txD=(TextView)findViewById(R.id.tvDepartureDate);
txR=(TextView)findViewById(R.id.tvReturnDate);
btnDepart = (Button)findViewById(R.id.btnDepart);
btnReturn = (Button)findViewById(R.id.btnReturn);
tr = (TableRow)findViewById(R.id.tableRow5);
btnSubmit = (Button)findViewById(R.id.btnSubmit);
btnClose = (Button)findViewById(R.id.btnClose);
noOfPassengersSpinner = (Spinner)findViewById(R.id.noOfPassengersSpinner);
departureSpinner = (Spinner)findViewById(R.id.departureSpinner);
returnSpinner = (Spinner)findViewById(R.id.returnSpinner);
tandCCB = (CheckBox)findViewById(R.id.tandCCB);
final Calendar dC = Calendar.getInstance();
final Calendar rC = Calendar.getInstance();
dYear = dC.get(Calendar.YEAR);
dMonth = dC.get(Calendar.MONTH);
dDay = dC.get(Calendar.DAY_OF_MONTH);
rYear = rC.get(Calendar.YEAR);
rMonth = rC.get(Calendar.MONTH);
rDay = rC.get(Calendar.DAY_OF_MONTH);
updateDisplay();
tandCCB.setOnCheckedChangeListener(new OnCheckedChangeListener()
{
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
{
if(isChecked){
btnSubmit.setEnabled(true);
}
else{
btnSubmit.setEnabled(false);
}
}
});
this.btnClose.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
finish();
System.exit(0);
}
});
this.btnSubmit.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
String depAir = departureSpinner.getSelectedItem().toString();
String desAir = returnSpinner.getSelectedItem().toString();
int numOfPass = Integer.parseInt(noOfPassengersSpinner.getSelectedItem().toString());
Bundle basket = new Bundle();
basket.putString("departureAir", depAir);
basket.putString("destenationAir", desAir);
basket.putInt("numOfPass", numOfPass);
basket.putString("depDate", txD.getText().toString());
String type = "";
String departureDateTemp = dYear+ ""+ ""+dMonth + ""+dDay;
int departureDateTemp2 = Integer.parseInt(departureDateTemp);
String returnDateTemp = rYear+ ""+ ""+rMonth + ""+rDay;
int returnDateTemp2 = Integer.parseInt(returnDateTemp);
if(returnDateTemp2 >= departureDateTemp2){
//MESSAGE
if(buttonR.isChecked()){
String returnDate = txR.getText().toString();
basket.putString("returnDate", returnDate);
type = "Return";
}
else{
type = "Oneway";
}
}
else{
btnSubmit.setEnabled(false);
}
basket.putString("type", type);
Intent intent = new Intent(context, Second.class);
intent.putExtra("basket", basket);
startActivity(intent);
}
});
this.buttonO.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
tr.setVisibility(View.GONE);
}
});
this.buttonR.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
tr.setVisibility(View.VISIBLE);
}
});
this.btnDepart.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
showDialog(dDATE_DIALOG_ID);
}
});
this.btnReturn.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
showDialog(rDATE_DIALOG_ID);
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private void updateDisplay() {
txD.setText(
new StringBuilder()
// Month is 0 based so add 1
.append(dYear).append("-")
.append(dMonth + 1).append("-")
.append(dDay).append(" ")
);
txR.setText(
new StringBuilder()
.append(rYear).append("-")
.append(rMonth + 1).append("-")
.append(rDay).append(" ")
);
}
private DatePickerDialog.OnDateSetListener dDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
dYear = year;
dMonth = monthOfYear;
dDay = dayOfMonth;
updateDisplay();
}
};
private DatePickerDialog.OnDateSetListener rDateSetListener =
new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year,
int monthOfYear, int dayOfMonth) {
rYear = year;
rMonth = monthOfYear;
rDay = dayOfMonth;
updateDisplay();
}
};
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case dDATE_DIALOG_ID:
return new DatePickerDialog(this,
dDateSetListener,
dYear, dMonth, dDay);
case rDATE_DIALOG_ID:
return new DatePickerDialog(this,
rDateSetListener,
rYear, dMonth, rDay);
}
return null;
}
}
これは私のコンソール出力です
[2013-04-26 13:37:44 - Assignment2] ------------------------------
[2013-04-26 13:37:44 - Assignment2] Android Launch!
[2013-04-26 13:37:44 - Assignment2] adb is running normally.
[2013-04-26 13:37:44 - Assignment2] Performing com.example.assignment2.MainActivity activity launch
[2013-04-26 13:37:44 - Assignment2] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'tester'
[2013-04-26 13:37:44 - Assignment2] Uploading Assignment2.apk onto device 'emulator-5554'
[2013-04-26 13:37:46 - Assignment2] Installing Assignment2.apk...
[2013-04-26 13:37:49 - Assignment2] Re-installation failed due to different application signatures.
[2013-04-26 13:37:49 - Assignment2] You must perform a full uninstall of the application. WARNING: This will remove the application data!
[2013-04-26 13:37:49 - Assignment2] Please execute 'adb uninstall com.example.assignment2' in a shell.
[2013-04-26 13:37:49 - Assignment2] Launch canceled!
前もって感謝します!