7

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:

Code with error

For comparison, here is some enum code from another, separate .java file that appears to be without error:

Code without error

Any assistance on this would be appreciated. Let me know if further clarification is needed.

coolDude
  • 647
  • 2
  • 11
  • 27

2 Answers2

2

It could be a couple of things but not related to enum, this is fine.

  1. Seems to me that unless Food does exist, it MUST be created
  2. If 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;

  3. It could be that your class name is not identical to you file name

    FoodArrayList

  4. Sometimes your IDE in this case Eclipse needs some help, try saving the file, closing it and opening it back up.

Esteban Rincon
  • 2,040
  • 3
  • 27
  • 44
-1

you have a semicolon missing at the end of the enum in the FoodArrayList class

harini
  • 11