-8

我正在尝试将长值传递给函数。但它说“令牌“长”上的语法错误,删除此令牌“。请解释这是什么以及何时发生这种错误

代码

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);
    }

请帮助我。

4

5 回答 5

4

更改printCSV(long btimeInMinutesSinceEpoch1,long ctimeInMinutesSinceEpoch);

printCSV(btimeInMinutesSinceEpoch1,ctimeInMinutesSinceEpoch); 

在将参数传递给函数时,您不需要在函数调用中指定输入参数的数据类型。

于 2013-10-11T12:28:25.813 回答
2

就是这一行:

    //error on this line 
    printCSV(btimeInMinutesSinceEpoch1, ctimeInMinutesSinceEpoch);
于 2013-10-11T12:27:24.897 回答
1

在调用方法时,您不需要指定输入参数的类型。因此改变这个:

printCSV(long btimeInMinutesSinceEpoch1,long ctimeInMinutesSinceEpoch); 

printCSV(btimeInMinutesSinceEpoch1,ctimeInMinutesSinceEpoch); 
于 2013-10-11T12:29:16.677 回答
0

利用:

printCSV(btimeInMinutesSinceEpoch1, ctimeInMinutesSinceEpoch); 

没有long

于 2013-10-11T12:29:35.427 回答
0
   long btimeInMinutesSinceEpoch1 = timeInMillisSinceEpoch1 / 1000;
    long ctimeInMinutesSinceEpoch = timeInMillisSinceEpoch / 1000;              

在上面的 2 行中,您已经声明btimeInMinutesSinceEpoch1ctimeInMinutesSinceEpochlong 类型。现在,在这一行 printCSV(long btimeInMinutesSinceEpoch1,long ctimeInMinutesSinceEpoch); 中,您再次声明相同的事情正确答案 printCSV(btimeInMinutesSinceEpoch1,ctimeInMinutesSinceEpoch);

于 2013-10-11T12:30:58.573 回答