-2

I have struggling a bit with those 2 small errors because Eclipse IDE "said so." I will point out the errors. To be honest, I don't know how to explain deeply about those errors. I thought they were simple and I cannot get the errors to go away.

    ScheduledExecutorService timer = Executors.newScheduledThreadPool (1);
    timer.scheduleAtFixedRate(new Runnable() 
    {
        public void run() 
        {
            if (lists. size ()> 0) 
            {
                boolean lighted = Lamp.valueOf(Road.this.name).isLighted(); //According to Eclipse, "The method valueOf(Class<T>, String) in the type Enum<Lamp> is not applicable for the arguments (String)"

                if (lighted) 
                {
                    System.out.println(lists.remove(0) + "is traversing!");
                }
            }
        }
    }, 1,1, TimeUnit. SECONDS);

and another error in my different class my package

public Lamp Blackout() 
{
    this.lighted = false;

    if (opposite != null) 
    {
        Lamp.valueOf(opposite).in.Blackout(); //in cannot be resolved or is not a field. It suggests me to create enum constant, which I did and it wouldn't work either. 
    }

    Lamp nextLamp = null;

    if (next != null) 
    {
        nextLamp = Lamp.valueOf(next);
        System.out.println("Green" + name () + "--------> switch to" + next);
        nextLamp.light();
    }
    return nextLamp;
}
CR9191
  • 51
  • 1
  • 7
  • 5
    We need to see short but full code example which will let us reproduce these problems. But generally errors aren't shown *because Eclipse IDE "said so."* but because there are problems in code. – Pshemo May 02 '15 at 20:02

2 Answers2

4

Your first error Lamp.valueOf(Road.this.name).isLighted();

//According to Eclipse, "The method valueOf(Class, String) in the type Enum is not applicable for the arguments (String)"

The method Lamp.valueOf() expects two arguments, first a class argument & then a String argument. You have just passed a String argument in the method that's why eclipse is throwing the error.

You Second error

Lamp.valueOf(opposite).in.Blackout();

//in cannot be resolved or is not a field.

It looks like an incorrect syntax to me. Check your code thoroughly. In your code methods are being chained. in should not be there. Or it may be a method in()

underdog
  • 4,447
  • 9
  • 44
  • 89
2

Shooting in the dark, because you haven't disclosed all relevant code, but you could try adding the missing parameter for valueOf here:

boolean lighted = Lamp.valueOf(Lamp.class, Road.this.name).isLighted();

and calling the in() method here:

Lamp.valueOf(Lamp.class, opposite).in(Blackout());

Please follow Java code style conventions; method names should start with a lowercase letter, so the blackout method signature should look like this instead:

public Lamp blackout()

Without seeing the code for the Lamp enum, it's impossible to know what the exact problem in the latter case is.

Mick Mnemonic
  • 7,808
  • 2
  • 26
  • 30