Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.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 迭代后未存储的日期_Android_Sqlite_Loops_Datetime_Jodatime - Fatal编程技术网

Android 迭代后未存储的日期

Android 迭代后未存储的日期,android,sqlite,loops,datetime,jodatime,Android,Sqlite,Loops,Datetime,Jodatime,我有一个迭代,根据另一个可能变化的值运行一定次数,这就是为什么我使用一个基于该值迭代的迭代,在该迭代中,每次迭代我在一个日期上加30天,然后将结果添加到一个表中 问题 我的第一个例子就是增加30天,这超出了迭代本身。这意味着我在迭代中的值没有被正确存储,但我不明白为什么 我已经检查了DateTime操作并显示了newdate的值,它显示了正确的日期,所以很可能是存储日期。但我不知道出了什么问题,它在迭代前工作,这让我感到困惑。为什么它不在迭代中执行?有人知道吗 前 实际迭代 终于发现了问题所在。

我有一个迭代,根据另一个可能变化的值运行一定次数,这就是为什么我使用一个基于该值迭代的迭代,在该迭代中,每次迭代我在一个日期上加30天,然后将结果添加到一个表中

问题

我的第一个例子就是增加30天,这超出了迭代本身。这意味着我在迭代中的值没有被正确存储,但我不明白为什么

我已经检查了DateTime操作并显示了newdate的值,它显示了正确的日期,所以很可能是存储日期。但我不知道出了什么问题,它在迭代前工作,这让我感到困惑。为什么它不在迭代中执行?有人知道吗

实际迭代


终于发现了问题所在。没有什么我的室友对我开了个玩笑,刚从外地回来,他向我解释了他是如何更改我的getDateDue以执行一个plusDateyS30来模拟我的代码的,这样当我调用AddPayment调用getDateDue时,它看起来会起作用,但实际上无论我做了什么,它只会在开始日期后增加30天一次

总结


室友是个混蛋,我的密码没问题。很抱歉这篇毫无意义的帖子。

我看不出有什么问题。我已经运行了您的代码,输出是04-28-2015 01:30:00 | 05-28-2015 01:30:00 | 06-27-2015 01:30:00 | 07-27-2015 01:30:00 | 08-26-2015 01:30:00 | 09-25-2015 01:30:00我也设置了断点,并在调试中运行并获得了正确的输出,但出于某种原因,每个条目插入的唯一内容是2015年4月29日。这意味着它在pay.setDateDuenewdate或db.AddPaymentpay中,但两者在迭代之外也以完全相同的方式使用,除了在迭代中并且工作正常之外。另外,在迭代中,我还有其他使用BigDecimal的操作,它们也是以同样的方式插入的,工作非常好?您是否在每次迭代时都创建它?不,我没有,pay实例是在onCreate开始时创建的,迭代在onCreate的底部。这不是问题。参见Astatine0936的答案
InitialDate | 3/29/2015
2ndDate     | 4/28/2015<-- This is what's stored which is pre-iteration
3rdDate     | 5/28/2015<-- This is what it's supposed to be after the iteration
so on and so forth....
    //Date stuff
    String startdate = (String.valueOf(Acc._date));
    DateTimeFormatter formatter = DateTimeFormat.forPattern("MM-dd-yyyy HH:mm:ss");
    DateTime dt = formatter.parseDateTime(startdate);
    DateTime startpoint = new DateTime(dt);
    DateTime whendue = startpoint.plusDays(30);
    DateTime foriteration = whendue;
    String formattedDate = whendue.toString(formatter);

    //Storing initial date
    pay.setDateDue(formattedDate);
    db.AddPayment(pay);
    while (i < j) {

            //Operation for Date Calculation
            DateTime ndt = foriteration.plusDays(30);
            foriteration = ndt;
            String newdate = ndt.toString(formatter);

            //Adding values to PayTable
            pay.setDateDue(newdate);
            db.AddPayment(pay);

            i++;
    }