Long cannot be dereferenced

System.currentTimeMillis() returns a primitive long not a object Long. So you cannot invoke the longValue() method or any method on it as primitive cannot be the object of method invocations.

Besides, it is useless to invoke longValue() as System.currentTimeMillis() returns already a long value.

This is better :


But in fact this condition : if(System.currentTimeMillis()==finish) could not be true even if System.currentTimeMillis() == finish in the while statement :

    while (found<3 && System.currentTimeMillis() < finish) {
        Command command = parser.getCommand();

Because between the end of the while statement and the condition evaluation :

if(System.currentTimeMillis() == finish), the time goes on elapsing.

So you should rather use :

 if(System.currentTimeMillis() >= finish){

Leave a Comment