0

嗨,我将这段代码添加到我的 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!

提前致谢!

4

2 回答 2

1

转到您的模拟器设置,卸载您的应用程序并重新安装。

于 2013-04-26T12:43:03.947 回答
0

只需按照
adb uninstall com.example.assignment2
命令行输出中所写的方式运行 coomand
并确保您adb在 PATH 环境中拥有,无论如何您都可以adbandroid-sdk/platform-tools文件夹中找到

并从您的 IDE 重新启动/重新运行您的项目

于 2013-04-26T12:43:45.927 回答