Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 比较日期java NullPointerException_Android_Date - Fatal编程技术网

Android 比较日期java NullPointerException

Android 比较日期java NullPointerException,android,date,Android,Date,我做这个函数是为了比较日期,但它只在第二次运行时运行一次。它给出了一个java空指针异常,我如何解决这个问题。我看过很多例子,看看是否可以用不同的方式来做,但我什么也没发现 try{ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); java.util.Date date1 = sdf.parse(datateste); java.util.Date date2 = sdf.p

我做这个函数是为了比较日期,但它只在第二次运行时运行一次。它给出了一个java空指针异常,我如何解决这个问题。我看过很多例子,看看是否可以用不同的方式来做,但我什么也没发现

 try{

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        java.util.Date date1 = sdf.parse(datateste);
        java.util.Date date2 = sdf.parse(data);
        java.util.Date date3 = sdf.parse(data2);

        System.out.println(sdf.format(date1));
        System.out.println(sdf.format(date2));

        if(date1.compareTo(date2)<0 || date1.compareTo(date3)>0){
            x=1;
        }else{
            System.out.pri
    }catch(ParseException ex){
        ex.printStackTrace();
    }

     if(checkEditText(inputdtestab) )
     {
      inputdtestab.setError("yipikaei");
     btnCreateProduct.setVisibility(View.INVISIBLE);

     }else if(x==1){

    inputdata.setError("asa");
    btnCreateProduct.setVisibility(View.INVISIBLE);

     }
    else if(checkEditText(quantidade)){

     quantidade.setError("mudfukkerrr");
     btnCreateProduct.setVisibility(View.INVISIBLE);

     }
     else{

     // ==========================================
     // make button visible.
     // use the method "setVisibility", not "setViewVisibility"
     // and "VISIBLE" in "View.VISIBLE" is in full cap:
     btnCreateProduct.setVisibility(View.VISIBLE);
    }

    }
所有代码

private TextWatcher myTextWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {}
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

public void afterTextChanged(Editable editable) {
  // invoke the following method here:
restricoes();


}
};

 @SuppressLint("NewApi")
@Override
 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_linha);



//Download JSON file AsyncTask
new DownloadJSON().execute();



 Intent i = getIntent();
id2 = i.getStringExtra(TAG_ID);
data = i.getStringExtra(DATA);
data2 = i.getStringExtra(DATA2);




 Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+1:00:00"));
 java.util.Date currentLocalTime = cal.getTime();
SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss"); 
//you can get seconds by adding  "...:ss" to it
time.setTimeZone(TimeZone.getTimeZone("GMT+1:00:00")); 
 String hr = time.format(currentLocalTime); 





 /** WebServices */
 inputdtestab= (EditText) findViewById(R.id.editestab);
 inputdata = (EditText) findViewById(R.id.editdata);
 inputhora = (EditText) findViewById(R.id.edithora);
 quantidade = (EditText) findViewById(R.id.editquantidade);

 inputhora.setText(hr);



 inputdtestab.addTextChangedListener(myTextWatcher);
 quantidade.addTextChangedListener(myTextWatcher);
 inputdata.addTextChangedListener(myTextWatcher);



 /   / Create button
  Button btnCreateProduct = (Button) findViewById(R.id.button2);

 // button click event
 btnCreateProduct.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {
// creating new product in background thread
new CreateNewProduct().execute();
}
});





  change_date=(Button)findViewById(R.id.button1);
 change_date.setOnClickListener(new OnClickListener() {


 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
    //triggers the DatePickerDialog
  showDialog(Date_Dialog_ID);
  }
  });



//getting current date
  cDate=Calendar.getInstance();
cDay=cDate.get(Calendar.DAY_OF_MONTH);
 cMonth=cDate.get(Calendar.MONTH);
cYear=cDate.get(Calendar.YEAR);
 //assigning the edittext with the current date in the beginning
 sDay=cDay;
sMonth=cMonth;
 sYear=cYear;
  updateDateDisplay(sYear,sMonth,sDay);


restricoes();
}


您似乎缺少一些有关
catch(ParseException ex)
的代码。请填写。什么是
datateste
<代码>数据。和
数据2
private TextWatcher myTextWatcher = new TextWatcher() {
public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {}
public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {}

public void afterTextChanged(Editable editable) {
  // invoke the following method here:
restricoes();


}
};

 @SuppressLint("NewApi")
@Override
 public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_linha);



//Download JSON file AsyncTask
new DownloadJSON().execute();



 Intent i = getIntent();
id2 = i.getStringExtra(TAG_ID);
data = i.getStringExtra(DATA);
data2 = i.getStringExtra(DATA2);




 Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+1:00:00"));
 java.util.Date currentLocalTime = cal.getTime();
SimpleDateFormat time = new SimpleDateFormat("HH:mm:ss"); 
//you can get seconds by adding  "...:ss" to it
time.setTimeZone(TimeZone.getTimeZone("GMT+1:00:00")); 
 String hr = time.format(currentLocalTime); 





 /** WebServices */
 inputdtestab= (EditText) findViewById(R.id.editestab);
 inputdata = (EditText) findViewById(R.id.editdata);
 inputhora = (EditText) findViewById(R.id.edithora);
 quantidade = (EditText) findViewById(R.id.editquantidade);

 inputhora.setText(hr);



 inputdtestab.addTextChangedListener(myTextWatcher);
 quantidade.addTextChangedListener(myTextWatcher);
 inputdata.addTextChangedListener(myTextWatcher);



 /   / Create button
  Button btnCreateProduct = (Button) findViewById(R.id.button2);

 // button click event
 btnCreateProduct.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {
// creating new product in background thread
new CreateNewProduct().execute();
}
});





  change_date=(Button)findViewById(R.id.button1);
 change_date.setOnClickListener(new OnClickListener() {


 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
    //triggers the DatePickerDialog
  showDialog(Date_Dialog_ID);
  }
  });



//getting current date
  cDate=Calendar.getInstance();
cDay=cDate.get(Calendar.DAY_OF_MONTH);
 cMonth=cDate.get(Calendar.MONTH);
cYear=cDate.get(Calendar.YEAR);
 //assigning the edittext with the current date in the beginning
 sDay=cDay;
sMonth=cMonth;
 sYear=cYear;
  updateDateDisplay(sYear,sMonth,sDay);


restricoes();
 //restriçoes ver
  private boolean checkEditText(EditText edit) {
 return edit.getText().length() == 0;
    }


   public void restricoes()  {
   int x=0;
  Button btnCreateProduct = (Button) findViewById(R.id.button2);
 datateste= inputdata.getText().toString();

 ntln("How to get here?");
    }