我试图将长值传递给函数。但是它说“令牌上的语法错误”很长“,删除此令牌”。请解释一下这是什么以及何时出现这种错误发生了
代码
public static void main(String[] args) {
Calendar currenttime = Calendar.getInstance();
Date date = currenttime.getTime();
long timeInMillisSinceEpoch = date.getTime();
long ctimeInMinutesSinceEpoch = timeInMillisSinceEpoch / 1000;
Calendar subhr = Calendar.getInstance();
subhr.add(Calendar.HOUR, -1);
Date date1 = subhr.getTime();
long timeInMillisSinceEpoch1 = date1.getTime();
long btimeInMinutesSinceEpoch1 = timeInMillisSinceEpoch1 / 1000;
//error on this line
printCSV(long btimeInMinutesSinceEpoch1,long ctimeInMinutesSinceEpoch);
}
public static void printCSV(long bdata,long cdata) {
try {
URL url = new URL(protocol + "://" + hostname + "/apiv2/csv.xml?username=" + userName + "&password=" + password + "&form_id=" + formId + "&begin_second="+bdata +"&end_second="+cdata);
HttpURLConnection urlCon = (HttpURLConnection) url.openConnection();
System.out.println(urlCon);
}
请帮助我。
答案 0 :(得分:4)
将printCSV(long btimeInMinutesSinceEpoch1,long ctimeInMinutesSinceEpoch);
更改为
printCSV(btimeInMinutesSinceEpoch1,ctimeInMinutesSinceEpoch);
在将参数传递给函数时,不需要在函数调用中指定输入参数的数据类型。
答案 1 :(得分:2)
就是这一行:
//error on this line
printCSV(btimeInMinutesSinceEpoch1, ctimeInMinutesSinceEpoch);
答案 2 :(得分:1)
在调用方法时,您无需指定输入参数的类型。因此改变这个:
printCSV(long btimeInMinutesSinceEpoch1,long ctimeInMinutesSinceEpoch);
到
printCSV(btimeInMinutesSinceEpoch1,ctimeInMinutesSinceEpoch);
答案 3 :(得分:0)
使用:
printCSV(btimeInMinutesSinceEpoch1, ctimeInMinutesSinceEpoch);
没有long
。
答案 4 :(得分:0)
long btimeInMinutesSinceEpoch1 = timeInMillisSinceEpoch1 / 1000;
long ctimeInMinutesSinceEpoch = timeInMillisSinceEpoch / 1000;
在上面的两行中,您已将btimeInMinutesSinceEpoch1
和ctimeInMinutesSinceEpoch
声明为长字型。现在这一行printCSV(long btimeInMinutesSinceEpoch1,long ctimeInMinutesSinceEpoch);
你再次宣布同样的事情
正确答案
printCSV(btimeInMinutesSinceEpoch1,ctimeInMinutesSinceEpoch);