[英]int set to zero generates new int by the same name tho
When I create an int COun
that increments with the following function, once it gets to desired int to set it back to zero, the COun
is set to zero and starts incrementing again until 10 but it increments another int, by the same name I assume. 当我创建一个使用以下函数递增的
int COun
,一旦将其设置为所需的int并将其设置回零,该COun
被设置为零,并再次开始递增直到10,但它会递增另一个int,其名称与我假设的相同。 Why does it do that? 为什么这样做呢?
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);
When you print out COun, you can tell it starts by just incrementing one COun, but then every time if sentence kicks in, it generates another COun counter. 当您打印出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
and it goes on weirdly like that, when either one becomes 10, it generates counting another one, along with the original, and on and on... 然后像这样怪异地继续下去,当其中一个变成10时,它会生成另一个与原始数一起计数的计数,然后不断地……
If you want to execute it once then you should call 如果要执行一次,则应致电
schedule(TimerTask task,Date time)
or 要么
schedule(TimerTask task, long delay)
scheduleAtFixedRate(TimerTask task,long delay,long period)
is when you need it to run repeatedly. scheduleAtFixedRate(TimerTask task,long delay,long period)
是需要重复运行的时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.