繁体   English   中英

设置为零的int生成具有相同名称的新int

[英]int set to zero generates new int by the same name tho

当我创建一个使用以下函数递增的int COun ,一旦将其设置为所需的int并将其设置回零,该COun被设置为零,并再次开始递增直到10,但它会递增另一个int,其名称与我假设的相同。 为什么这样做呢?

Timer timer = new Timer();

    timer.scheduleAtFixedRate(new TimerTask()
    {
        public void run()
        {
           // Your code

            counterr++;
            System.out.println("COun "+counterr);
           // System.out.println("Refresh?  "+refresh);
             if(counterr>10){
                 json = jParser.makeHttpRequest(url_all_products, "GET", params);
                 Intent i = new Intent(getApplicationContext(), AllProductsActivity.class);
                 startActivity(i);
                 counterr=0;

             }
        }
    }, delay, period);

当您打印出COun时,可以说只是增加一个COun而已,但是每当句子出现时,它都会生成另一个COun计数器。

12-20 18:50:16.170: I/System.out(10465): COun 1

12-20 18:50:17.071: I/System.out(10465): COun 2

12-20 18:50:18.082: I/System.out(10465): COun 3

12-20 18:50:19.083: I/System.out(10465): COun 4

12-20 18:50:20.084: I/System.out(10465): COun 5

12-20 18:50:21.085: I/System.out(10465): COun 6

12-20 18:50:22.086: I/System.out(10465): COun 7

12-20 18:50:23.077: I/System.out(10465): COun 8

12-20 18:50:24.078: I/System.out(10465): COun 9

12-20 18:50:25.079: I/System.out(10465): COun 10

12-20 18:50:26.080: I/System.out(10465): COun 11

12-20 18:50:27.071: I/System.out(10465): COun 1

12-20 18:50:28.082: I/System.out(10465): COun 2

12-20 18:50:29.073: I/System.out(10465): COun 3

12-20 18:50:30.083: I/System.out(10465): COun 4

12-20 18:50:31.084: I/System.out(10465): COun 5

12-20 18:50:31.405: I/System.out(10465): COun 1

12-20 18:50:32.085: I/System.out(10465): COun 6

12-20 18:50:32.406: I/System.out(10465): COun 2

12-20 18:50:33.086: I/System.out(10465): COun 7

12-20 18:50:33.407: I/System.out(10465): COun 3

12-20 18:50:33.407: I/System.out(10465): COun 8

12-20 18:50:33.407: I/System.out(10465): COun 4

12-20 18:50:33.407: I/System.out(10465): COun 9

12-20 18:50:33.407: I/System.out(10465): COun 5

然后像这样怪异地继续下去,当其中一个变成10时,它会生成另一个与原始数一起计数的计数,然后不断地……

如果要执行一次,则应致电

schedule(TimerTask task,Date time)

要么

schedule(TimerTask task, long delay)

scheduleAtFixedRate(TimerTask task,long delay,long period)是需要重复运行的时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM