有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java不断得到非法的类型错误的开始,我如何才能纠正这一点并继续前进?

下面是我的部分代码;由于常量illegal start of type错误(在if语句的行上),我无法编译。我能做些什么来改变它

public class Job
{

    boolean jobsCompleted = false;
    Job firstJob = getCurrentJob();
    String jobName = firstJob.getName();
    int jobDuration = firstJob.getDuration();
    if (!myJob.isEmpty()&& jobDuration > 0 && jobDuration <= myTotalDuration) 
    //this is where i am getting the error, highlighting red before the 'if' statement.

共 (1) 个答案

  1. # 1 楼答案

    您需要将其中一些代码放入一个方法中,因为在一个方法中只能有一个if

    比如

    public class AClass {
        void aMethod() {
            if( true == true ) {
                //do something
            }
        }
    }