简体   繁体   中英

Java cascade of errors in object code when compiling

I'm trying to compile a java program, however I get a cascade of errors stating

"Error expected", "illegal start of type", "class, interface or enum expected" from the file containing methods/constructors for an object called Task.

From what I can gather online these errors occur when statements are made outside of a class or method etc. but I haven't done any of that.

The code was working fine before, all I have done to Task.java is add a few basic get and set methods and change the name of some of the variables.

What's more is that I can't view all the errors in cmd. For some reason I can only scroll up so far, so I can't even attempt to pin point the source.

public class Task
{
// private member variables
private int CriticalTime;
private int TaskTime;
private int id;
private int numDependency;
private int day;
private boolean generic;
private boolean isComplete;
private boolean isCritical;
private boolean ignore;
private boolean dummy;
private boolean isScheduled;
private int[] dependency;

public Task()
{
    CriticalTime = 0;
    TaskTime = 0;
    id = 0;
    numDependency = 0;
    day = 0;
    generic = false;
    isComplete = false;
    isCritical = false;
    ignore = false;
    dummy = false;
    isScheduled = false;
    int[] dependency; 
    return;
}

public Task(int x, int y, int ID, int NumDependency, int Day, boolean Generic, boolean IsComplete, boolean IsCritical, boolean Ignore, boolean Dummy, boolean IsScheduled, int[] Dependency)
{
    CriticalTime = x;
    TaskTime = y;
    id = ID;
    numDependency = NumDependency;
    day = Day;
    generic = Generic;
    isComplete = IsComplete;
    isCritical = IsCritical;
    ignore = Ignore;
    dummy = Dummy;
    isScheduled = IsScheduled;
    this.dependency = Dependency;
    return;
}

public void setTask(int x, int y, int ID, int NumDependency, int Day, boolean Generic, boolean IsComplete, boolean IsCritical, boolean Ignore, boolean Dummy boolean IsScheduled, int[] Dependency)
 {
    CriticalTime = x;
    TaskTime = y;
    id = ID;
    numDependency = NumDependency;
    day = Day;
    generic = Generic;
    isComplete = IsComplete;
    isCritical = IsCritical;
    ignore = Ignore;
    dummy = Dummy;
    isScheduled = IsScheduled;
    this.dependency = Dependency;
}
 public void setTask(int[] Dependency)
 {
    CriticalTime = 0;
    day = 0;
    generic = false;
    isComplete = false;
    isCritical = false;
    ignore = false;
    dummy = false;
    isScheduled = false;
    this.dependency = Dependency;
}

public int getCriticalTime()
{
    return CriticalTime;
}

public int getTaskTime()
{
    return TaskTime;
}

public int getTaskID()
{
    return id;
}

 public int getNumDependency()
{
    return numDependency;
}

   public boolean getGenericBoolean()
{
    return generic;
}
   public boolean getIsCompleteBoolean()
{
    return isComplete;
}
   public boolean getIsCriticalBoolean()
{
    return isCritical;
}
   public boolean getIgnoreBoolean()
{
    return ignore;
}
   public boolean getIsScheduled()
{
    return isScheduled;
}
  public boolean getDummy()
{
    return dummy;
}
  public int getDay()
{
    return day;
}
   public int getDependency(int x)
{
    return dependency[x];
}

   public void setGenericBoolean(boolean Generic)
{
    generic = Generic;
}
   public void setIsCompleteBoolean(boolean IsComplete)
{
    isComplete = IsComplete;
}
    public void setIsCriticalBoolean(boolean IsCritical)
{
    isCritical = IsCritical;
}
    public void setIgnoreBoolean(boolean Ignore)
{
    ignore = Ignore;
}

    public void setIsScheduled(boolean IsScheduled)
{
    isScheduled = IsScheduled;
}

    public void setCriticalTime(int A)
{
    CriticalTime = A;
}
    public void setCriticalTime(int A, int B)
{
    CriticalTime = A + B;
}
    public void setDependency(int i, int A)
{
    dependency[i]=A;
}
    public void setTaskTime(int A)
{
    TaskTime = A;
}
    public void setTaskID(int A)
{
    id = A;
}
    public void setNumDep(int A)
{
    numDependency = A;
}
  public void setDummy(boolean Dummy)
{
    dummy = Dummy;
}
  public void setDay(int i)
{
    day = i;
}

}

Sorry if this is badly formatted or has unnecessary methods etc., I'm very much a novice.

Not a direct answer, but a guide how to solve such things: simply comment out 95% of that code.

In other words: the more code you try to compile, the easier it is that a simple syntactic error turns into an error message that is not pointing to the correct place directly.

Thus:

  • you simply start by running the compiler much more often. Write 5 lines of code (of which you think: this should compile) - then run the compiler. Fix bugs. And so on
  • and as said: when you have such a huge thing and you can't translate error messages into meaningful information: try to isolate where the problem comes from.

And beyond that: read about clean code . That practice advocates for example to have a maximum of 3 parameters for a method. And surprise: such missing commas, as in your case are much easier to spot when there are only 2 of them for 3 parameters - instead of 11 for 12 parameters as in your case).

Seriously: your "syntax" problems are just a symptom of the real problem: and that lies in the way how you are designing your class and its methods.

There is a , missing on boolean Dummy boolean IsScheduled, of setTask . It should be

public void setTask(int x, int y, int ID, int NumDependency, 
  int Day, boolean Generic, boolean IsComplete, boolean IsCritical, 
  boolean Ignore, boolean Dummy, boolean IsScheduled, int[] Dependency)
{
...
}

This is a type of error that is easily spotted if you were using an IDE to program.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM