I am trying to define an enum within a class but Eclipse continues to underline my code in the lovely red color. Here is what my code looks like for the most part:
package campusvilleFoodBank;
import java.util.NoSuchElementException;
import java.util.Scanner;
public class FoodArrayList {
public enum Days {SUN, MON, TUE, WED, THUR, FRI, SAT}
private Food [] foodArray;
private int iterator;
private boolean startIndexing;
private static final int MAX = 24;
public FoodArrayList(){
foodArray = new Food [MAX];
iterator = 0;
}
public FoodArrayList(int arraySize){
foodArray = new Food [arraySize];
iterator = 0;
}
//Rest of code, with more complicated methods here
}
I must be missing something very simple, it's likely to be a syntax error.... The code that follows involves methods such as my toString()
, some sorting methods for the foodArray
instance variable, and things along those lines. I do not have a main method defined. I know that I can define an enum within a class definition and all of the code I've seen elsewhere is written nearly exactly the same as to what I have. However, Eclipse does not seem to recognize even the enum
declaration and I don't believe I need to import anything.
Here is what I see in Eclipse for the code I have an error with:
For comparison, here is some enum code from another, separate .java file that appears to be without error:
Any assistance on this would be appreciated. Let me know if further clarification is needed.
It could be a couple of things but not related to enum
, this is fine.
Food
does exist, it MUST be createdIf it does exist, then it must reside in a different package, which in turn you have to import
it like this
import package_name.package2.Food;
It could be that your class
name is not identical to you file
name
FoodArrayList
Sometimes your IDE
in this case Eclipse
needs some help, try saving the file, closing it and opening it back up.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With