我使用这种方法,我得到了 while 循环堆栈溢出。没有错误消息或崩溃。我在我的日志猫中得到了这个:
05-18 20:17:16.528: W/InputEventReceiver(19831): Attempted to finish an input event but the input event receiver has already been disposed.
当我将此代码放入我的 while 布尔值中时:
data.numberOfSameDateRows(selectedDay) != 0
循环很好。但是当我像下面这样使用它时,我得到了堆栈溢出。
if(data.numberOfSameDateRows(selectedDay) != 0)
i=0;
else
i++;
感谢您的帮助:)
这是我的代码:
DataBaseMain data = new DataBaseMain(this);
data.open();
SimpleDateFormat dateFormatter = new SimpleDateFormat("d-MMMM-yyyy");
String dateWanted = getCorrectDate(removeSpinner);
Date wantedDate = new Date();
int i = 0;
try {
wantedDate = dateFormatter.parse(dateWanted);
} catch (ParseException e) {
e.printStackTrace();
}
Calendar myCal = new GregorianCalendar();
myCal.setTime(wantedDate);
Date newDate = myCal.getTime();
String selectedDay = dateFormatter.format(newDate);
if(dateWanted.equals("all") == false){
do{
if(data.numberOfSameDateRows(selectedDay) != 0)
i=0;
else
i++;
myCal.add(Calendar.DAY_OF_YEAR, 7);
newDate = myCal.getTime();
selectedDay = dateFormatter.format(newDate);
}
while(i < 5);
public int numberOfSameDateRows(String date){
int i = 0;
String[] columns = new String[]{COLUMN_DATE};
Cursor c = ourDatabase.query(TABLE_NAME, columns, COLUMN_DATE + "= '" + date + "'", null, null, null, null);
if(c.getCount() >= 1)
for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()){
i++;
}
return i;
}